How refresh datatable related to options list

Hi, I have two components, options list and datatable. Datatable has define groupDataSource and

query=select e from publisher$DocTypes e where e.register.id = :ds$registerDs.id. in cuba studio.

Now I don’t know how I might refresh datatable component when item in options list component is changeing.

Thanks

You need to define listener for your OptionsList:


@Override
public void init(Map<String,Object> params){
	/*...*/
	myOptList.addValueChangeListener(e->myTableReloadLogic(e))
}

ok thanks !

I try this, but I don’t know what exactly must to be in myTableReloadLogic functions.

I create this code but it isn’t working correct.

public class DocTypesBrowse extends AbstractLookup {

@Inject
private GroupTable docTypesesTable;

@Inject
private OptionsList registersesOptionsList;

@Inject
private GroupDatasource<DocTypes, Integer> docTypesesDs;

@Inject
private CollectionDatasource<Registers, Integer> registersesDs;

@Override
public void init(Map<String, Object> params) {
	// TODO Auto-generated method stub
	super.init(params);
	registersesOptionsList.addValueChangeListener(event -> {
		if (event.getPrevValue() != null) {
			if (event.getPrevValue().equals(event.getValue()))
				return;
			docTypesesTable.refresh();
		}

	});
}

}

It is pretty much depends on what you selecting in your Options List = couldn’t really say what logic you want:
But i prepare little example with can be useful if i understand your task correctly
image

xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://caption"
        class="com.company.enerstroymain.web.main.transstation.Screen"
        messagesPack="com.company.enerstroymain.web.main.transstation">
    <dsContext>
        <collectionDatasource id="contractsDs"
                              class="com.company.enerstroymain.entity.Contract"
                              view="_base">
            <query>
                <![CDATA[select e from enerstroymain$Contract e]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="objectsDs"
                              class="com.company.enerstroymain.entity.Object"
                              view="object-full-view">
            <query>
                <![CDATA[select e from enerstroymain$Object e
where e.contract.id = :custom$contractId]]>
            </query>
        </collectionDatasource>
    </dsContext>
    <dialogMode height="600"
                width="800"/>
    <layout>
        <hbox id="hbox"
              expand="table"
              height="100%"
              width="100%">
            <optionsList id="optionsList"
                         optionsDatasource="contractsDs"/>
            <table id="table"
                   height="212px">
                <columns>
                    <column id="contract"/>
                    <column id="locality"/>
                </columns>
                <rows datasource="objectsDs"/>
            </table>
        </hbox>
    </layout>
</window>
Controler
package com.company.enerstroymain.web.main.transstation;

import com.company.enerstroymain.entity.Contract;
import com.company.enerstroymain.entity.Object;
import com.haulmont.bali.util.ParamsMap;
import com.haulmont.cuba.gui.components.AbstractWindow;
import com.haulmont.cuba.gui.components.OptionsList;
import com.haulmont.cuba.gui.data.CollectionDatasource;

import javax.inject.Inject;
import java.util.Map;
import java.util.UUID;

public class Screen extends AbstractWindow {
    @Inject protected OptionsList optionsList;
    @Inject protected CollectionDatasource<Object,UUID> objectsDs;

    @Override
    public void init(Map<String, java.lang.Object> params){
        super.init(params);
        optionsList.addValueChangeListener(e->{
            if(e.getValue() != null){
                objectsDs.refresh(ParamsMap.of("contractId",(Contract)e.getValue()));
            }
        });
    }
}

As you can see: i used :custom parameter for my table datasource and passed it when options List changes value

Thanks for example is ok. I have another question. How might I set cursor on the first element of optionsList.
I set focus on optionsList component but cursor not set on any position when open the window with optionsList up.

Try to use setValue()

I tried your tips. No effect.

Depends on - what value you settled for yours optionsList:

screen after initialization

image

I rewrited screen for testing. Now table uses areasDs and zonesDs in optionsList, hope it didn’t confuse you.

@Override
public void init(Map<String,Object> params){
    super.init(params);

    optionsList.addValueChangeListener(e->{
        if(e.getValue() != null) areasDs.refresh(ParamsMap.of("zoneId",(Zone)e.getValue()));
    });

    zonesDs.refresh();
    optionsList.setValue(zonesDs.getItem(zonesDs.getItemIds().iterator().next()));
    optionsList.requestFocus();
}

Thanks for example is ok

I have last question. I look on your last example and I try explain my problem.
I add position to areasDs by standard browser’s action and I want fiil column zoneId value from column id zonesDs currently select position in optionsList. I try do it but I need access to optionsList component in class extends by AbstractEditor.

For that case you need to write your own “addAction”.
You cans see in docs how to implement your actions

There is a few ways, one of them:
Create new Action for your table “myAddAction” in your case, if i understend you currectly
2018-05-16_18-26-53
After [4] in your controller you will see
2018-05-16_18-28-13
And further goes your code, smth like:

DocsType newDt = metadata.create(DocsType.class); //ofc you need to inject Metadata service first
newDt.setRegister((Register)registersesOptionsList.getValue()); //null warning
/*..commit it maby?..*/
docTypesesDs.addItem(newDt);

And add Button for it:
2018-05-16_18-29-13

Thanks
I used simple method.

@Named(“docTypesesTable.create”)
private CreateAction docTypesesTableCreate;

.and I set init entity value by

Map<String, Object> init = new
init.put(“register”, register);
docTypesesTableCreate.setInitialValues(init);

1 Like

Hi

I have another question.How might I change browse controler window related with LookupPickerField ?
How I have DocTypesBrowse and I want to change on DocTypesSimpleBrowse.

Well, you can define action with will open editor for your entity
btw you probably should create new theme for non-related to current topic question