Announcement

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

    Pagination in ListGrid

    Hi,
    I have difficulties in retrieving data from my server page by page in a list grid. I get the first page, but when i get to the end of the list grid, the client doesn't ask for the next window of records.

    Here is my client code:
    Code:
    isc.DataSource.create({
        ID:"testRows",
        dataURL:"testTotalRows.php",
        dataFormat:"json",
        recordXPath: "response/data",
        transformRequest : function (dsRequest) {
            if (dsRequest.operationType == "fetch") {
                var params = {
                   startRow : dsRequest.startRow,
                   endRow : dsRequest.endRow
                };
                // combine paging parameters with criteria
                return isc.addProperties({}, dsRequest.data, params);
            }
         },
        transformResponse: function(dsResponse, dsRequest, data) {
        	 if (dsRequest.operationType == "fetch") {
        	 	dsResponse.startRow = isc.XMLTools.selectNumber(data, "response/startRow");
        	 	dsResponse.endRow = isc.XMLTools.selectNumber(data, "response/endRow");
        	 	dsResponse.totalRows = isc.XMLTools.selectNumber(data, "response/totalRows");
        	 	dsResponse.status = isc.XMLTools.selectNumber(data, "response/status");
        	 }
        	 return dsResponse;
         },
        fields:[
            { name : "a", title: "ColA"},
            { name : "b", title: "ColB"},
        ]
    });
    
    isc.ListGrid.create({
        ID:"adGrid",
        left:100, top:50,
        width:150,
        height:100,
        showAllRecords:true,
        alternateRecordStyles:true,
        dataSource:"testRows",
        dataPageSize: 5,
        autoFetchData:true
    });
    The server side responds with the following json message:
    Code:
    {"response":
         {"status":0,"startRow":0,"endRow":7,"totalRows":100,
         "data":[{"a":"A0","b":"B0"},{"a":"A1","b":"B1"},{"a":"A2","b":"B2"},  
                   {"a":"A3","b":"B3"},{"a":"A4","b":"B4"},{"a":"A5","b":"B5"},
                   {"a":"A6","b":"B6"}]
         }
    }
    What have I missed in my code?

    #2
    Isomorphic, can I please have your input on this?
    Is there any other information that i have to provide, besides the client code and the server response?

    Thank you

    Comment


      #3
      Ok, I've figure it out how to solve this.

      I've used the RestDataSource, and removed recordXPath, transformRequest and transformResponse arguments from my old datasource.
      Also, I've removed "showAllRecords:true" from the list grid.

      For those who want to use the transformReponse with RestDataSource, beware that there is a slight modification than when you use it in a normal DataSouce (more information on http://www.smartclient.com/docs/8.0/a/b/c/go.html#method..RestDataSource.transformResponse)

      Comment

      Working...
      X