Announcement

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

    listGrid.getGroupTree().findIndex() does not work with more than 50 records

    Browser: Firefox 52.0
    Smartgwt : Version 6.1p, Built 2017-09-05
    GWT: 2.7

    I am trying to select a listgrid record that has been grouped. I use the listgrid.getGroupTree().findIndex() to locate the record. This works as long as I only group max of 50 records. If my server returns 51 then the select no longer works. Below is the code snippet. I have tried doing different approaches. One was to use the dataArrivedCallback() which made no difference. One was to capture when the GoupBy was finished and then try the select. Nothing seemed to work.

    MyProject.java

    public class MyProject implements EntryPoint {

    ListGrid grid = null;

    public void onModuleLoad() {
    VLayout mainContainer = new VLayout();
    mainContainer.setWidth(800);
    mainContainer.setHeight(500);
    mainContainer.addMember(buildListGrid());
    RootPanel.get("mainContainer").add(mainContainer);
    fetchData();
    }

    private ListGrid biuldListGrid() {
    grid = new ListGrid();
    ListGridField name = new ListGridField("name", "Name");
    ListGridField id = new ListGridField("id", "ID", 100);

    grid.setFields(id, name);
    MyDS ds = new MyDS("id");
    grid.setDataSource(ds);
    grid.setGroupStartOpen(GroupStartOpen.ALL);
    grid.groupBy("name");
    grid.setHeight(400);
    }

    protectred void fetchData() {
    grid.fetchData(new Criteria(), new DSCallback() {
    @Override
    public void execute(DSResponse response, Object rawData, DSRequest request) {
    selectEntry();
    }
    }
    }

    protected void selectEntry() {
    int index = grid.getGroupTree().findIndex("id", "10");
    grid.selectRange(index, index+1);
    }

    }

    public class MyDS extends RestDataSource {
    public MyDS() {
    this("myds");
    }

    public MyDS(String id) {
    setID(id);
    setClientOnly(false);
    setDataFormat(DSDataFormat.JSON);
    setJsonPrefix("");
    setJsonSuffix("");
    OperationBinding fetch = new OperationBinding();
    fetch.setOperationType(DSOperationType.FETCH);
    DSRequest fetchProps = new DSRequest();
    fetchProps.setHttpMethod("GET");
    fetch.setRequestProperties(fetchProps);

    setOperationBindings(fetch);

    init();
    }

    protected void init() {
    DataSourceField id = new DataSourceField("id", "ID");
    id.setPrimaryKey(true);
    id.setHidden(true);
    DataSourceField name = new DataSourceTextField("name", "Name");

    setFields(id, name);
    }
    }

    I create the data as follows on my Server:

    public List<MyData> createDummyData() {
    List<MyData> data = new ArrayList<MyData>();
    int cnt = 51;
    int skip = 0;
    String name = "name"+0;

    for (int i=0; i<cnt; i++) {
    MyData d = new MyData();
    if (skip > 2) {
    name = "name" + i;
    skip = 0;
    }

    skip++;
    d.setId(i+"");
    d.setName(name);
    data.add(d);
    }

    return data;

    }

    public class MyData {

    private String id;
    private String name;

    public String getId() {
    return id;
    }

    public void setId(String id) {
    this.id = id;
    }
    public String getName() {
    return name;
    }

    public void setName(String name) {
    this.name = name;
    }



    }

    #2
    Grouping is done incrementally in batches of 50 to avoid browser warnings about long running scripts, so you need to wait for the groupingComplete event before you access the group tree.

    Comment


      #3
      Thank you. So I modified the buildListGrid() to add catching the onGroupByComplete() but it doesn't seem to be getting called. I don't see the SC.say() message getting displayed. Any reasons why that would be?

      BTW, the response json is as follows:

      {"response" : {
      "status":0,
      "startRow":0,
      "endRow":50,
      "totalRows":50,
      "internalCnt":0,
      "data" : [{"name": "name0", "id":"0"}, ....and so on ]
      }
      }


      private ListGrid biuldListGrid() {
      grid = new ListGrid();
      ListGridField name = new ListGridField("name", "Name");
      ListGridField id = new ListGridField("id", "ID", 100);

      grid.setFields(id, name);
      MyDS ds = new MyDS("id");
      grid.setDataSource(ds);
      grid.setGroupStartOpen(GroupStartOpen.ALL);
      grid.groupBy("name");
      grid.setHeight(400);

      grid.addGroupByCompleteHandler(new GroupByCompleteHandler() {
      @Override
      public void onGroupByComplete(GroupByCompleteEvent event) {
      SC.say("in group by complete handler");
      }

      });
      }

      Comment


        #4
        The GroupByCompleteHandler did NOT get invoked. Please advise why or what I need to do to fix it.

        Comment


          #5
          GroupByCompleteHandler only runs in response to a groupBy() (when you first group the grid), not a regroup(), which is what happens new new data arrives from the server. We're considering now how best to provide notification in your situation.

          Comment


            #6
            If you slightly modify your sample, you can get the GroupByCompleteHandler to work. The idea is to remove the existing groupBy() call you have in your sample code, and instead call groupBy() only after the fetch is complete, in the callback:

            Code:
                protected void fetchData() {
                    grid.fetchData(new Criteria(), new DSCallback() {
                        @Override
                        public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
                            grid.groupBy("name");
                        }
                    });
                }
            Then you can call your selectEntry() method from the GroupByCompletehandler:
            Code:
                    grid.addGroupByCompleteHandler(new GroupByCompleteHandler() {
                        @Override
                        public void onGroupByComplete(GroupByCompleteEvent event) {
                            SC.say("in group by complete handler");
                            if (grid.getIsGrouped()) selectEntry();
                        }
                    });

            Comment

            Working...
            X