Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

  • Listgrid setInitialSort not sorting with DisplayField

    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



    Click image for larger version

Name:	Screenshot (95).png
Views:	1
Size:	4.4 KB
ID:	255906

  • #2
    We don't support client-side sorting by the displayField of a ListGridField if the optionDataSource for that field is defined but different than the "main" DS of the grid. This is because, in general, we can't assume that such DataSources are fully cached on the client (even though in your specific case you're using client-only DataSources).

    So, we'd recommend that you use real (i.e. not client-only) DataSources, and define the displayField in the DataSource definition (xml) together with a foreignKey, as described here. You can see an example of this approach in the "units" field of the supplyItemCustom DataSource featured in the SGWT EE Showcase Batch Uploader sample (use "View Source").

    Comment

    Working...
    X