Wrong usage - see QuickStart Guide, Data Binding chapter - you should pass in fields to setFields() with all settings already configured.
Announcement
Collapse
No announcement yet.
X
-
I tried to use this code:
Code:public void onModuleLoad() { final ListGrid listGrid = new ListGrid(); listGrid.setWidth(700); listGrid.setHeight(224); listGrid.setAlternateRecordStyles(true); DataSource ds = DataSource.get("worldDS"); listGrid.setDataSource(ds); listGrid.setAutoFetchData(true); listGrid.setShowFilterEditor(true); listGrid.setCanEdit(true); listGrid.setEditEvent(ListGridEditEvent.CLICK); listGrid.setCanRemoveRecords(true); [B] ComboBoxItem cbi = new ComboBoxItem("continent"); cbi.setOptionDataSource(DataSource.get("Continent")); cbi.setOptionOperationId("byName"); cbi.setDisplayField("name"); cbi.setValueField("name"); ListGridField continent = new ListGridField("continent"); continent.setFilterEditorType(cbi); continent.setEditorType(cbi); listGrid.setFields(new ListGridField("countryCode") ,new ListGridField("countryName") ,new ListGridField("capital") ,new ListGridField("government") ,continent ,new ListGridField("independence") ,new ListGridField("area") ,new ListGridField("population") ,new ListGridField("gdp") ,new ListGridField("member_g8") ); [/B] IButton newButton = new IButton("Add New"); newButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { listGrid.startEditingNew(); } }); VLayout layout = new VLayout(15); layout.addMember(listGrid); layout.addMember(newButton); layout.draw(); }
1) When clicking on a record to edit, the continent appears as the index number and not the value map (see attachment editCell).
2) When I use the pulldown to filter, it doesn't filter correctly because it's using "name" instead of "continent" for the criteria. Here is the log for that one.
Code:=== 2012-09-19 13:57:05,597 [ec-4] DEBUG XML - Parsed XML from (in memory stream): 1ms === 2012-09-19 13:57:05,598 [ec-4] DEBUG RPCManager - Processing 1 requests. === 2012-09-19 13:57:05,599 [ec-4] DEBUG RPCManager - Request #1 (DSRequest) payload: { criteria:{ name:"Africa" }, operationConfig:{ dataSource:"worldDS", operationType:"fetch", textMatchStyle:"substring" }, startRow:0, endRow:75, componentId:"isc_ListGrid_0", appID:"builtinApplication", operation:"worldDS_fetch", oldValues:{ name:"Africa" } } === 2012-09-19 13:57:05,599 [ec-4] INFO IDACall - Performing 1 operation(s) === 2012-09-19 13:57:05,600 [ec-4] DEBUG AppBase - [builtinApplication.worldDS_fetch] No userTypes defined, allowing anyone access to all operations for this application === 2012-09-19 13:57:05,600 [ec-4] DEBUG AppBase - [builtinApplication.worldDS_fetch] No public zero-argument method named '_worldDS_fetch' found, performing generic datasource operation === 2012-09-19 13:57:05,600 [ec-4] INFO SQLDataSource - [builtinApplication.worldDS_fetch] Performing fetch operation with criteria: {name:"Africa"} values: {name:"Africa"} === 2012-09-19 13:57:05,600 [ec-4] INFO SQLDataSource - [builtinApplication.worldDS_fetch] derived query: SELECT $defaultSelectClause FROM $defaultTableClause WHERE $defaultWhereClause AND $defaultJoinWhereClause === 2012-09-19 13:57:05,601 [ec-4] DEBUG SQLDataSource - [builtinApplication.worldDS_fetch] Executing row count query: SELECT COUNT(*) FROM $defaultTableClause WHERE $defaultWhereClause AND $defaultJoinWhereClause === 2012-09-19 13:57:05,601 [ec-4] DEBUG SQLDataSource - [builtinApplication.worldDS_fetch] Eval'd row count query: SELECT COUNT(*) FROM worldDS, Continent WHERE ('1'='1') AND Continent.pk = worldDS.continent === 2012-09-19 13:57:05,601 [ec-4] DEBUG PoolableSQLConnectionFactory - [builtinApplication.worldDS_fetch] DriverManager fetching connection for Mysql via jdbc url jdbc:mysql://localhost/fermat?user=fermatcapital&password=fermatwandq&zeroDateTimeBehavior=convertToNull === 2012-09-19 13:57:05,601 [ec-4] DEBUG PoolableSQLConnectionFactory - [builtinApplication.worldDS_fetch] Passing JDBC URL only to getConnection === 2012-09-19 13:57:05,609 [ec-4] DEBUG PoolableSQLConnectionFactory - [builtinApplication.worldDS_fetch] Returning pooled Connection === 2012-09-19 13:57:05,610 [ec-4] INFO SQLDriver - [builtinApplication.worldDS_fetch] Executing SQL query on 'Mysql': SELECT COUNT(*) FROM worldDS, Continent WHERE ('1'='1') AND Continent.pk = worldDS.continent === 2012-09-19 13:57:05,610 [ec-4] DEBUG SQLDataSource - [builtinApplication.worldDS_fetch] Using SQL Limit query === 2012-09-19 13:57:05,610 [ec-4] DEBUG SQLDataSource - [builtinApplication.worldDS_fetch] SQL windowed select rows 0->75, result size 75. Query: SELECT worldDS.area, worldDS.capital, worldDS.continent, worldDS.countryCode, worldDS.countryName, worldDS.gdp, worldDS.government, worldDS.independence, worldDS.member_g8, worldDS.pk, worldDS.population, Continent.name AS continentName FROM worldDS, Continent WHERE ('1'='1') AND Continent.pk = worldDS.continent LIMIT 0, 75 === 2012-09-19 13:57:05,611 [ec-4] DEBUG PoolableSQLConnectionFactory - [builtinApplication.worldDS_fetch] DriverManager fetching connection for Mysql via jdbc url jdbc:mysql://localhost/fermat?user=fermatcapital&password=fermatwandq&zeroDateTimeBehavior=convertToNull === 2012-09-19 13:57:05,611 [ec-4] DEBUG PoolableSQLConnectionFactory - [builtinApplication.worldDS_fetch] Passing JDBC URL only to getConnection === 2012-09-19 13:57:05,619 [ec-4] DEBUG PoolableSQLConnectionFactory - [builtinApplication.worldDS_fetch] Returning pooled Connection === 2012-09-19 13:57:05,632 [ec-4] INFO DSResponse - [builtinApplication.worldDS_fetch] DSResponse: List with 75 items === 2012-09-19 13:57:05,633 [ec-4] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8 === 2012-09-19 13:57:05,634 [ec-4] DEBUG RPCManager - non-DMI response, dropExtraFields: false === 2012-09-19 13:57:05,646 [ec-4] INFO Compression - /Performances/performances/sc/IDACall: 17494 -> 3720 bytes === 2012-09-19 15:30:57,979 [ec-7] INFO Download - done streaming: /Users/Shared/test/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Performances/performances/sc/skins/Enterprise/images/DynamicForm/unchecked.png
Comment
-
We can't tell what the names of the fields in the DataSources are - the UI needs to match these names.
1) whatever is set as the displayField is what's shown. Seems like your optionDataSource must have integers stored in the "name" field.
2) You seem to be using "name" now, whereas the name of the field was "continentName" in the DataSource in the last snippet we've seen.
Comment
-
Now I switched the optionDataSource to "worldDS", used displayField="continentName", valuefield="continent" and everything filters ok. Table looks good.
However, the pulldown literally shows all the values in the column of worldDS. Is that expected behavior? I would like to have the pulldown give a sorted list of the possible values for a continent.
Code:ComboBoxItem cbi = new ComboBoxItem("continent"); cbi.setOptionDataSource(DataSource.get("worldDS")); cbi.setDisplayField("continentName"); cbi.setValueField("continent"); ListGridField continent = new ListGridField("continent"); continent.setFilterEditorType(cbi); continent.setEditorType(cbi); listGrid.setFields(new ListGridField("countryCode") ,new ListGridField("countryName") ,new ListGridField("capital") ,new ListGridField("government") ,continent ,new ListGridField("independence") ,new ListGridField("area") ,new ListGridField("population") ,new ListGridField("gdp") ,new ListGridField("member_g8") );
Comment
-
Isomorphic, I believe I got it...THANK YOU!
I have a solution without any programmatic calls. I can do it via with just using ds.xml specs. The key for me is that all dsRequests are in the context of the worldDS datasource. Filtering criterias are created in the context of the Continent datasource since I'm using optionDataSource. Thus the field references must cross from one datasource to another. Correct me if I'm not right.
So I just created a field in Continent.ds.xml file that mirrored the one we created in worldDS.ds.xml. Now filtering works perfectly, and my pulldown only has unique continent entries.
Here are the highlights of the specifications (the ones you need to enable filtering via ComboBoxItem).
This is in my worldDS.ds.xml file:
Code:<field name="continentName" includeFrom="Continent.name" hidden="true"/> <field name="continent" type="integer" foreignKey="Continent.pk" optionDataSource="Continent" optionOperationId="byName" valueField="pk" displayField="continentName" filterEditorType="ComboBoxItem" editorType="SelectItem" />
Code:<operationBindings> <operationBinding operationId="byName" operationType="fetch"> <selectClause> pk, name, name as continentName </selectClause> <orderClause> name asc </orderClause> </operationBinding> </operationBindings>
Here are the two ds.xml files in it's entirety:
worldDS.ds.xml:
Code:<DataSource ID="worldDS" serverType="sql" tableName="worldDS" > <fields> <field name="pk" type="sequence" hidden="true" primaryKey="true" /> <field name="countryCode" type="text" title="Code" required="true" /> <field name="countryName" type="text" title="Country" required="true" /> <field name="capital" type="text" title="Capital" /> <field name="government" type="text" title="Government" length="500" /> <field name="continentName" includeFrom="Continent.name" hidden="true"/> <field name="continent" type="integer" foreignKey="Continent.pk" optionDataSource="Continent" optionOperationId="byName" valueField="pk" displayField="continentName" filterEditorType="ComboBoxItem" editorType="SelectItem" /> <field name="independence" type="date" title="Nationhood" /> <field name="area" type="float" title="Area (km2)" /> <field name="population" type="integer" title="Population" /> <field name="gdp" type="float" title="GDP ($M)" /> <field name="member_g8" type="boolean" title="G8" /> </fields> </DataSource>
Code:<DataSource ID="Continent" serverType="sql" tableName="Continent" > <fields> <field name="pk" type="sequence" hidden="true" primaryKey="true" /> <field name="name" type="text" title="Continent" required="true" /> </fields> <operationBindings> <operationBinding operationId="byName" operationType="fetch"> <selectClause> pk, name, name as continentName </selectClause> <orderClause> name asc </orderClause> </operationBinding> </operationBindings> </DataSource>
Comment
-
ISSUE
I am running into some issues where the filter dropdown and what I type in sometimes conflicts. I.e.,
- type in a partial string and I get appropriate filtering
then
- Use the filter pulldown and I get appropriate filtering
However, I still have the old partial string in the filter text box.
My New Strategy?
I noticed that the Large Value Map (LVM) example doesn't behave this way. Thus, I'm attempting to mimic the LargeValue example with our Continent example. It seems that we have replaced the LVM customSQL clause with foreignKey and includeFrom's.
Now do I just mimic the programmatic calls in LVM?
Comment
-
PROBLEM
Filtering/editing works fine. However, when typing in the filtering ComboBoxItem, the options of values are not being filtered by the pulldown. I just get all the possible values in the pulldown.
How does one get the ComboBoxItem to filter the possible values in the pulldown?
SETUP
To make sure we're on the same page, I'm on:
GWT-2.4.0
Smartgwtpower-3.0p
eclipse - Indigo
I have modified the Large Value Map (LVM) example to the Showcase:Grids:Filtering:Filter example.
Here's the code:
Source
Code:public void onModuleLoad() { final ListGrid listGrid = new ListGrid(); listGrid.setWidth(700); listGrid.setHeight(224); listGrid.setAlternateRecordStyles(true); DataSource ds = DataSource.get("worldDS"); listGrid.setDataSource(ds); listGrid.setAutoFetchData(true); listGrid.setShowFilterEditor(true); listGrid.setCanEdit(true); listGrid.setEditEvent(ListGridEditEvent.CLICK); listGrid.setCanRemoveRecords(true); ListGridField continent = new ListGridField("continent"); continent.setFilterEditorType(new ComboBoxItem()); continent.setDisplayField("continentName"); // Added this so that values show up for this column in the grid continent.setValueField("continent"); FormItem fi = new FormItem(){ { setOptionDataSource(DataSource.get("Continent")); setOptionOperationId("filter"); setDisplayField("continentName"); setValueField("continent"); } }; // Had to use fi instead of SelectItem so that the pulldown in the // editing mode of the grid will show values. // continent.setEditorType(new SelectItem()); continent.setEditorType(fi); continent.setFilterEditorProperties(fi); listGrid.setFields(new ListGridField("countryCode") ,new ListGridField("countryName") ,new ListGridField("capital") ,new ListGridField("government") ,continent ,new ListGridField("independence") ,new ListGridField("area") ,new ListGridField("population") ,new ListGridField("gdp") ,new ListGridField("member_g8") ); IButton newButton = new IButton("Add New"); newButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { listGrid.startEditingNew(); } }); VLayout layout = new VLayout(15); layout.addMember(listGrid); layout.addMember(newButton); layout.draw(); }
Code:<DataSource ID="worldDS" serverType="sql" tableName="worldDS" > <fields> <field name="pk" type="sequence" hidden="true" primaryKey="true" /> <field name="countryCode" type="text" title="Code" required="true" /> <field name="countryName" type="text" title="Country" required="true" /> <field name="capital" type="text" title="Capital" /> <field name="government" type="text" title="Government" length="500" /> <field name="continentName" includeFrom="Continent.name" hidden="true"/> <field name="continent" type="integer" foreignKey="Continent.pk" displayField="continentName" /> <field name="independence" type="date" title="Nationhood" /> <field name="area" type="float" title="Area (km2)" /> <field name="population" type="integer" title="Population" /> <field name="gdp" type="float" title="GDP ($M)" /> <field name="member_g8" type="boolean" title="G8" /> </fields> </DataSource>
Continent.ds.xml
Code:<DataSource ID="Continent" serverType="sql" tableName="Continent" > <fields> <field name="pk" type="sequence" hidden="true" primaryKey="true" /> <field name="name" type="text" title="Continent" required="true" /> </fields> <operationBindings> <operationBinding operationId="filter" operationType="fetch"> <selectClause> pk, pk as continent, name, name as continentName </selectClause> <orderClause> name asc </orderClause> </operationBinding> </operationBindings> </DataSource>
Comment
-
If you're going to set up additional output fields from your select via the SQL "as" operator you need to declare those as fields in the DataSource. For security reasons, filter criteria that are submitted to the server that don't correspond to any DataSource field are ignored. Otherwise you could filter on fields you're not meant to see.
Also, you shouldn't be calling both setEditorType and setFilterEditorProperties with the same FormItem instance - reusing items in this way is not allowed (there should be a warning in the logs).
Comment
-
No change in behavior. The pulldown still is not being filtered by what one types.
I changed the code as follows per your suggestion. Here's the snippet.
Code:continent.setDisplayField("continentName"); continent.setValueField("continent"); continent.setEditorType(new SelectItem(){ { setOptionDataSource(DataSource.get("Continent")); setOptionOperationId("filter"); setDisplayField("continentName"); setValueField("continent"); } }); continent.setFilterEditorType( new ComboBoxItem(){ { setOptionDataSource(DataSource.get("Continent")); setOptionOperationId("filter"); setDisplayField("continentName"); setValueField("continent"); } });
Comment
-
AAAHHHH!
It all works now! THANK YOU!!
I used customSelectExpression to add those fields.
For others, here's the code that works:
SOURCE
Code:public void onModuleLoad() { final ListGrid listGrid = new ListGrid(); listGrid.setWidth(700); listGrid.setHeight(224); listGrid.setAlternateRecordStyles(true); DataSource ds = DataSource.get("worldDS"); listGrid.setDataSource(ds); listGrid.setAutoFetchData(true); listGrid.setShowFilterEditor(true); listGrid.setCanEdit(true); listGrid.setEditEvent(ListGridEditEvent.CLICK); listGrid.setCanRemoveRecords(true); ListGridField continent = new ListGridField("continent"); continent.setDisplayField("continentName"); continent.setValueField("continent"); continent.setEditorType(new SelectItem() { { setOptionDataSource(DataSource.get("Continent")); setOptionOperationId("filter"); setDisplayField("continentName"); setValueField("continent"); } }); continent.setFilterEditorType(new ComboBoxItem() { { setOptionDataSource(DataSource.get("Continent")); setOptionOperationId("filter"); setDisplayField("continentName"); setValueField("continent"); } }); listGrid.setFields(new ListGridField("countryCode"), new ListGridField( "countryName"), new ListGridField("capital"), new ListGridField("government"), continent, new ListGridField( "independence"), new ListGridField("area"), new ListGridField("population"), new ListGridField("gdp"), new ListGridField("member_g8")); IButton newButton = new IButton("Add New"); newButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { listGrid.startEditingNew(); } }); VLayout layout = new VLayout(15); layout.addMember(listGrid); layout.addMember(newButton); layout.draw(); }
Code:<DataSource ID="worldDS" serverType="sql" tableName="worldDS" > <fields> <field name="pk" type="sequence" hidden="true" primaryKey="true" /> <field name="countryCode" type="text" title="Code" required="true" /> <field name="countryName" type="text" title="Country" required="true" /> <field name="capital" type="text" title="Capital" /> <field name="government" type="text" title="Government" length="500" /> <field name="continentName" includeFrom="Continent.name" hidden="true"/> <field name="continent" type="integer" foreignKey="Continent.pk" displayField="continentName" /> <field name="independence" type="date" title="Nationhood" /> <field name="area" type="float" title="Area (km2)" /> <field name="population" type="integer" title="Population" /> <field name="gdp" type="float" title="GDP ($M)" /> <field name="member_g8" type="boolean" title="G8" /> </fields> </DataSource>
Code:<DataSource ID="Continent" serverType="sql" tableName="Continent" > <fields> <field name="pk" type="sequence" hidden="true" primaryKey="true" /> <field name="name" type="text" title="Continent" required="true" /> <field name="continent" customSelectExpression="pk" /> <field name="continentName" customSelectExpression="name" /> </fields> <operationBindings> <operationBinding operationId="filter" operationType="fetch"> <orderClause> name asc </orderClause> </operationBinding> </operationBindings> </DataSource>
Comment
-
I have found an issue in the CombBoxItem of the filter. If I have set the following:
Code:listGrid.setFilterOnKeypress(true);
Is this expected behavior with setFilterOnKeypress set to true?
Comment
-
Modification of the Large Value Map example in Showcase EE:JavaDataIntegration:SQL
The environment is:
1) GWT-2.4.0
2) smartgwtpower-3.0p 9/18/2012 build
3) Eclipse Indigo
The modifications are:
1) Datasources are in a MySQL database,
2) The code below in Bold has been added: orderListGrid.setFilterOnKeypress(true);
Code:public void onModuleLoad() { DataSource dataSource = DataSource.get("largeValueMap_orderItem"); final DataSource feds = DataSource.get("supplyItem"); final ListGrid orderListGrid = new ListGrid(); orderListGrid.setWidth(550); orderListGrid.setHeight(224); orderListGrid.setDataSource(dataSource); orderListGrid.setAutoFetchData(true); orderListGrid.setShowFilterEditor(true); orderListGrid.setCanEdit(true); ListGridField orderIdField = new ListGridField("orderID"); ListGridField itemIdField = new ListGridField("itemID", "Item Name"); itemIdField.setWidth("50%"); itemIdField.setEditorType(new SelectItem()); itemIdField.setFilterEditorType(new ComboBoxItem()); itemIdField.setDisplayField("itemName"); FormItem feProps = new FormItem() {{ setOptionDataSource(feds); }}; itemIdField.setFilterEditorProperties(feProps); ListGridField quantityField = new ListGridField("quantity"); ListGridField unitPriceField = new ListGridField("unitPrice"); orderListGrid.setFields(orderIdField, itemIdField, quantityField, unitPriceField); [B]orderListGrid.setFilterOnKeypress(true);[/B] orderListGrid.draw(); }
Comment
Comment