Hello,
I am using data grid component with inline editor. I have a column with a lookup field with some values which I passed dynamically.
Is there a way to populate the lookup field with some query so that I don’t have to pass those values dynamically?
browser XML:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
caption="msg://browseCaption"
class="com.company.zeusv2.web.networkmapping.NetworkMappingBrowse"
focusComponent="networkMappingsDataGrid"
lookupComponent="networkMappingsDataGrid"
messagesPack="com.company.zeusv2.web.networkmapping">
<dsContext>
<collectionDatasource id="networkMappingsDs"
class="com.company.zeusv2.entity.NetworkMapping"
view="_local">
<query>
<![CDATA[select e from zeusv2$NetworkMapping e]]>
<filter>
<and>
<c>e.network = :custom$networkSearch</c>
<c>e.type = :custom$typeSearch</c>
<c>e.value = :custom$valueSearch</c>
</and>
</filter>
</query>
</collectionDatasource>
</dsContext>
<dialogMode height="600"
width="800"/>
<layout expand="networkMappingsDataGrid"
spacing="true">
<label value="Network Mapping Table"/>
<groupBox caption="Custom filter"
orientation="horizontal"
spacing="true">
<lookupField id="networkLookup"
caption="Network Search"
inputPrompt="Select Network"/>
<lookupField id="typeLookup"
caption="Type Search"
inputPrompt="Select Type"/>
<lookupField id="valueLookup"
caption="Value Search"
inputPrompt="Select Value"/>
<button id="applyCustomFilterBtn"
caption="Apply custom filter"
invoke="applyCustomFilter"/>
</groupBox>
<dataGrid id="networkMappingsDataGrid"
datasource="networkMappingsDs"
editorEnabled="true"
width="100%">
<columns>
<column property="network"/>
<column property="type"/>
<column property="keyValue"/>
<column property="value"/>
<column property="updated"/>
</columns>
</dataGrid>
</layout>
</window>
Controller:
package com.company.zeusv2.web.networkmapping;
import com.company.zeusv2.entity.NetworkMapping;
import com.haulmont.cuba.core.entity.IdProxy;
import com.haulmont.cuba.gui.components.AbstractLookup;
import com.haulmont.cuba.gui.components.DataGrid;
import com.haulmont.cuba.gui.components.LookupField;
import com.company.zeusv2.entity.NetworkMapping;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
import javax.inject.Inject;
import java.util.*;
public class NetworkMappingBrowse extends AbstractLookup {
@Inject
private DataGrid<NetworkMapping> networkMappingsDataGrid;
@Inject
private ComponentsFactory componentsFactory;
@Inject
private LookupField networkLookup;
@Inject
private LookupField typeLookup;
@Inject
private CollectionDatasource<NetworkMapping, IdProxy> networkMappingsDs;
@Inject
private LookupField valueLookup;
@Override
public void init(Map<String, Object> params) {
List<String> networkList = Arrays.asList("AFFILINET", "ZANOX", "WEBGAINS", "NETAFFILIATION");
List<String> typeList = Arrays.asList("COMMISSION_STATUS","COMMISSION_TYPE","RELATIONSHIP_STATUS", "COUNTRY");
List<String> valueList = Arrays.asList("CONFIRMED","REJECTED","DELAYED", "SALE");
networkMappingsDataGrid.getColumnNN("network")
.setEditorFieldGenerator((datasource, property) -> {
LookupField networkLookupField = componentsFactory.createComponent(LookupField.class);
networkLookupField.setDatasource(datasource, property);
networkLookupField.setOptionsList(networkList);
return networkLookupField;
});
networkMappingsDataGrid.getColumnNN("type")
.setEditorFieldGenerator((datasource, property) -> {
LookupField typeLookupField = componentsFactory.createComponent(LookupField.class);
typeLookupField.setDatasource(datasource, property);
typeLookupField.setOptionsList(typeList);
return typeLookupField;
});
networkMappingsDataGrid.getColumnNN("value")
.setEditorFieldGenerator((datasource, property) -> {
LookupField valueLookupField = componentsFactory.createComponent(LookupField.class);
valueLookupField.setDatasource(datasource, property);
valueLookupField.setOptionsList(valueList);
return valueLookupField;
});
networkLookup.setOptionsList(networkList);
typeLookup.setOptionsList(typeList);
valueLookup.setOptionsList(valueList);
}
public void applyCustomFilter() {
Map<String, Object> params = new HashMap<>();
params.put("networkSearch", networkLookup.getValue());
params.put("typeSearch", typeLookup.getValue());
params.put("valueSearch", valueLookup.getValue());
networkMappingsDs.refresh(params);
}
}
Any suggestions will be appreciated.
Regards
Sanchit