views:

2165

answers:

3

I try to understand how use server-side Pagination for Dynamic Data (I see example : http://developer.yahoo.com/yui/examples/datatable/dt_dynamicdata.html).

My problem is I can not customize my request, when I try the pagination, my request is : qct-list.htmlsort=geneid&dir=asc&startIndex=50&result=25

The request should be in the following form : qct-list.html?name=cd4&symbol=cd4&start=0&limit=25 or qct-list.html?name=cd4&symbol=cd4&start=25&limit=50 ...

Here is a copy (part) of my code :

        var myColumnDefs = [
            {key:"geneid", label:"Gene", sortable:true},
            {key:"name", label:"Name", sortable:true},
            {key:"symbol", label:"Symbol", sortable:true},
            {key:"lastupdated", label:"Last Updated", formatter:"date", sortable:true},
            {key:"lastmodified", label:"Last Modified", formatter:"date", sortable:true}
        ];

        var myDataSource = new YAHOO.util.DataSource("qct-list.html");
        myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
        myDataSource.connXhrMode = "queueRequests";
        myDataSource.responseSchema = {
            resultsList: "geneItemList",
            fields: ["col","qv","limit","start","geneid","name","symbol","lastupdated","lastmodified"],
            metaFields: {
                    totalRecords: "totalRecords" // Access to value in the server response
                }
        };

        var qctPaginator = new YAHOO.widget.Paginator({
            rowsPerPage: 25,
            totalRecords : YAHOO.widget.Paginator.VALUE_UNLIMITED,
            template: YAHOO.widget.Paginator.TEMPLATE_ROWS_PER_PAGE,
            rowsPerPageOptions: [25,50,75,100]
                        });

        var myRequestBuilder = function(ostate, oSelf) {
            oState = oState || {pagination:null};
            var name = Dom.get('dt_input_name').value;
            var symbol = Dom.get('dt_input_symbol').value;
            var start = (oState.pagination) ? oState.pagination.recordOffset : 0;
            var limit = (oState.pagination) ? oState.pagination.rowsPerPage : 25;
            return  "?name=" + name + "&symbol"+ symbol + "&start=" + start + "&limit=" + limit;
        }

        var oConfigs = {
            dynamicData: true, // Enables dynamic server-driven data
            selectionMode: "single",
            paginator: qctPaginator ,
            generateRequest : myRequestBuilder,
            paginationEventHandler : YAHOO.widget.DataTable.handleDataSourcePagination,
            initialRequest: "?name=&symbol=&start=0&limit="
        };

        var myGeneListTable = new YAHOO.widget.DataTable("geneListTable", myColumnDefs, myDataSource, oConfigs);

        myGeneListTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
            oPayload.totalRecords = oResponse.meta.totalRecords;
            return oPayload;
        }

Can someone explain how to use the pagination with DataTable and how to personalize request ?

A: 

I think you need to swap the declaraion of oConfigs and myRequestBuilder around so that

var myRequestBuilder = ...

var oConfigs = ...
Adrian
+1  A: 

I almost managed to make it work my pagination. My RequestBuilder now works fine, I get the request I need : qct-list.html?name=interferon&symbol=&start=25&limit=25

Here the new code :

var myColumnDefs = [
 {key:"geneid", label:"Gene", sortable:true},
 {key:"name", label:"Name", sortable:true},
 {key:"symbol", label:"Symbol", sortable:true},
 {key:"lastupdated", label:"Last Updated", formatter:"date", sortable:true},
 {key:"lastmodified", label:"Last Modified", formatter:"date", sortable:true}
];

var myDataSource = new YAHOO.util.DataSource("qct-list.html");
 myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
 myDataSource.connXhrMode = "queueRequests";
 myDataSource.responseSchema = {
 resultsList: "geneItemList",
 fields: ["col","qv","limit","start","geneid","name","symbol","lastupdated","lastmodified"],
 metaFields: {
                    totalRecords: "totalRecords" // Access to value in the server response
                }
};

var qctPaginator = new YAHOO.widget.Paginator({
    rowsPerPage: 25,
    rowsPerPageOptions: [25,50,75,100]
    });

var myRequestBuilder = function(oState,oSelf)
{
 oState = oState || {pagination:null, sortedBy:null};
 // var sort = (oState.sortedBy) ? oState.sortedBy.key : "geneid";
 // var dir = (oState.sortedBy && oState.sortedBy.dir === YAHOO.widget.DataTable.CLASS_DESC) ? "desc" : "asc";
    var start = (oState.pagination != null) ? oState.pagination.recordOffset : 0;
    var limit = (oState.pagination != null) ? oState.pagination.rowsPerPage : 25;
    var name = Dom.get('dt_input_name').value || "";
    var symbol = Dom.get('dt_input_symbol').value || "";

    return '?name='+ name + '&symbol=' + symbol + '&start='+ start + '&limit=' + limit;

}

var oConfigs = {
  initialRequest: "?name=interferon&symbol=&start=&limit=",
  dynamicData: true, // Enables dynamic server-driven data
  selectionMode: "single",
  paginator: qctPaginator,
  generateRequest : myRequestBuilder
};

var myGeneListTable = new YAHOO.widget.DataTable("geneListTable", myColumnDefs, myDataSource, oConfigs);

 myGeneListTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {

    if (oPayload == undefined) {
        oPayload = {};  
    }
    oPayload.totalRecords = oResponse.meta.totalRecords;
    return oPayload;
 }
Fabien Barbier
Unfortunately, I get an error just after :I[T] is undefined[Break on this error] if(L){return this.getLastTdEl(L);}}}retu...==D.CLASS_ASC)?D.CLASS_DESC:D.CLASS_ASC;An idea about this error ?I found my error. The problem comes from my controller. At the first request all goes well, but when I use pagination, my controller modify totalRecords (and return the same value as rowsPerPage). Which produces the error described above...
Fabien Barbier
I fix this bug. Now my controller return the same totalRecords for each query. And all is good.
Fabien Barbier
A: 

i have same problem,thanx.

baoaya