I have listgrid with setOptionDataSource in listgridfield. when I set initial sort on listgrid it sort with valuefield not display field. I want initial sort with displayfield.
I am using smartgwt version 6.1
heare is a full code of my program:
package test.supdev.client;
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.SortSpecifier;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.SortDirection;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
public class SupDevDemo implements EntryPoint {
public void onModuleLoad() {
DataSource mainDS = new MainSource("mainDS");
DataSource countryDS = new CountryDataSource("countryDS");
ListGrid listGrid = new ListGrid();
listGrid.setWidth100();
listGrid.setCanMultiSort(true);
listGrid.setDataSource(mainDS);
SortSpecifier[] sortSpecifiers=new SortSpecifier[1];
sortSpecifiers[0]=new SortSpecifier("country", SortDirection.ASCENDING);
listGrid.setInitialSort(sortSpecifiers);
ListGridField name = new ListGridField("name","Name");
ListGridField country = new ListGridField("country","Country");
country.setDisplayField("Name");
country.setValueField("ID");
country.setOptionDataSource(countryDS);
country.setAutoFetchDisplayMap(true);
country.setSortByDisplayField(true);
listGrid.setAutoFetchData(true);
listGrid.setFields(name,country);
listGrid.show();
}
// Country Data Store
class CountryDataSource extends DataSource {
public CountryDataSource(String id) {
setID(id);
DataSourceTextField ID = new DataSourceTextField("ID","ID");
ID.setPrimaryKey(true);
DataSourceTextField Name = new DataSourceTextField("Name","Name");
setFields(ID, Name);
setClientOnly(true);
// Populate Country DataSource via RPC or Cached data
Record record = new Record();
record.setAttribute("ID", "01");
record.setAttribute("Name", "usa");
this.addData(record);
record = new Record();
record.setAttribute("ID", "02");
record.setAttribute("Name", "india");
this.addData(record);
record = new Record();
record.setAttribute("ID", "03");
record.setAttribute("Name", "france");
this.addData(record);
}
}
class MainSource extends DataSource {
public MainSource(String id) {
setID(id);
DataSourceTextField nameField = new DataSourceTextField("name","Name",300);
nameField.setPrimaryKey(true);
DataSourceTextField country = new DataSourceTextField("country","Country",100);
setFields(nameField,country);
setClientOnly(true);
// Populate Country DataSource via RPC or Cached data
Record record = new Record();
record.setAttribute("name", "jatin");
record.setAttribute("country", "01");
this.addData(record);
record = new Record();
record.setAttribute("name", "Mayur");
record.setAttribute("country", "02");
this.addData(record);
record = new Record();
record.setAttribute("name", "abc");
record.setAttribute("country", "03");
this.addData(record);
}
}
}
here is output of my program:
it should be:
france
india
usa
I am using smartgwt version 6.1
heare is a full code of my program:
package test.supdev.client;
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.SortSpecifier;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.SortDirection;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
public class SupDevDemo implements EntryPoint {
public void onModuleLoad() {
DataSource mainDS = new MainSource("mainDS");
DataSource countryDS = new CountryDataSource("countryDS");
ListGrid listGrid = new ListGrid();
listGrid.setWidth100();
listGrid.setCanMultiSort(true);
listGrid.setDataSource(mainDS);
SortSpecifier[] sortSpecifiers=new SortSpecifier[1];
sortSpecifiers[0]=new SortSpecifier("country", SortDirection.ASCENDING);
listGrid.setInitialSort(sortSpecifiers);
ListGridField name = new ListGridField("name","Name");
ListGridField country = new ListGridField("country","Country");
country.setDisplayField("Name");
country.setValueField("ID");
country.setOptionDataSource(countryDS);
country.setAutoFetchDisplayMap(true);
country.setSortByDisplayField(true);
listGrid.setAutoFetchData(true);
listGrid.setFields(name,country);
listGrid.show();
}
// Country Data Store
class CountryDataSource extends DataSource {
public CountryDataSource(String id) {
setID(id);
DataSourceTextField ID = new DataSourceTextField("ID","ID");
ID.setPrimaryKey(true);
DataSourceTextField Name = new DataSourceTextField("Name","Name");
setFields(ID, Name);
setClientOnly(true);
// Populate Country DataSource via RPC or Cached data
Record record = new Record();
record.setAttribute("ID", "01");
record.setAttribute("Name", "usa");
this.addData(record);
record = new Record();
record.setAttribute("ID", "02");
record.setAttribute("Name", "india");
this.addData(record);
record = new Record();
record.setAttribute("ID", "03");
record.setAttribute("Name", "france");
this.addData(record);
}
}
class MainSource extends DataSource {
public MainSource(String id) {
setID(id);
DataSourceTextField nameField = new DataSourceTextField("name","Name",300);
nameField.setPrimaryKey(true);
DataSourceTextField country = new DataSourceTextField("country","Country",100);
setFields(nameField,country);
setClientOnly(true);
// Populate Country DataSource via RPC or Cached data
Record record = new Record();
record.setAttribute("name", "jatin");
record.setAttribute("country", "01");
this.addData(record);
record = new Record();
record.setAttribute("name", "Mayur");
record.setAttribute("country", "02");
this.addData(record);
record = new Record();
record.setAttribute("name", "abc");
record.setAttribute("country", "03");
this.addData(record);
}
}
}
here is output of my program:
it should be:
france
india
usa
Comment