[ 19 posts ] Go to page 1, 2 Next

VS_0511

  • Username: vs0511
  • Joined: Fri May 07, 2010 8:20 am
  • Posts: 51
  • Offline
  • Profile

Server Side Pagination : pages links disappear

Post Posted: Sun Sep 26, 2010 9:43 am
+0-
Hi,

I was implementing pagination and used client-side first and everything was fine, I obtained my DataSource, defined Paginator in configuration and displayed the table.

then the requirements changed and I had to implement server-side pagination. I defined configuration like that :
Code:
var myConfig = {               
             dynamicData: true,
             height:"400px",             
             initialRequest: "sort=account&dir=asc&startIndex=0&results=500",
             paginator: new YAHOO.widget.Paginator({ rowsPerPage:25 }),
             sortedBy : { key:'account', dir: YAHOO.widget.DataTable.CLASS_ASC}
            };


Data Source :
Code:
    "recordsReturned": 100,
 {
   [
     .....
   ],
   
   "totalRecords": 500,
    "startIndex": 0,
    "dir": "asc",
    "pageSize": 10
}


My DataSource contains "totalRecords" and all other necessary meta data.
and at that point pages links disappeared.

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: Server Side Pagination : pages links disappear

Post Posted: Sun Sep 26, 2010 11:15 pm
+0-
If your data is not enclosed in curly braces, that is an error, but I guess it is just a copying error.

This might help:

http://www.yuiblog.com/blog/2010/09/02/ ... lean-code/

VS_0511

  • Username: vs0511
  • Joined: Fri May 07, 2010 8:20 am
  • Posts: 51
  • Offline
  • Profile

Re: Server Side Pagination : pages links disappear

Post Posted: Mon Sep 27, 2010 3:39 am
+0-
Satyam,

thank you for answering. I don't think it's a problem with the JSON because the DataTable is generated correctly - I have 100 records on the screen. The problem is that totalRecords number is 500 and I suppose to have 5 links on the page and I don't. Somehow the system doesn't recognize that there are more records available than initially loaded.

Josh Johnston

  • Username: Tree2054
  • Joined: Fri Sep 10, 2010 11:41 am
  • Posts: 25
  • IRC: Trii
  • Offline
  • Profile

Re: Server Side Pagination : pages links disappear

Post Posted: Mon Sep 27, 2010 5:51 am
+0-
VS_0511,

did you define your own handleDataReturnPayload() in your datatable to pass the pagination data generated by the server to your object?

did you define your paging fields in the meta section of your datasource?

VS_0511

  • Username: vs0511
  • Joined: Fri May 07, 2010 8:20 am
  • Posts: 51
  • Offline
  • Profile
Tags:

Re: Server Side Pagination : pages links disappear

Post Posted: Mon Sep 27, 2010 9:21 am
+0-
1.
myDataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
oPayload.totalRecords = oResponse.meta.totalRecords;
return oPayload;
}; - yes, I defined it.

********************

My paging fields in the meta section of the DataSource :

"recordsReturned": 100,
"totalRecords": 500,
"startIndex": 0,
"dir": "asc",
"pageSize": 5

------------------------------------

My DataSource is valid, I tested it in JSONlint.

Josh Johnston

  • Username: Tree2054
  • Joined: Fri Sep 10, 2010 11:41 am
  • Posts: 25
  • IRC: Trii
  • Offline
  • Profile

Re: Server Side Pagination : pages links disappear

Post Posted: Mon Sep 27, 2010 9:35 am
+0-
I had similar issues with my table. One of the pieces I put in place was this extended handler
Code:
handleDataReturnPayload: function(request, response, data) {
    // needed for pagination
    var rm = response.meta;
    data.totalRecords                   = rm.totalRecords;
    data.pagination.recordOffset    = rm.startIndex;
    data.pagination.rowsPerPage  = rm.pageSize;

    // handles the UI state to show the sorting
    var DT = YAHOO.widget.DataTable;
    data.sortedBy.dir = (rm.dir == 'desc' ? DT.CLASS_DESC : DT.CLASS_ASC);
    data.sortedBy.key = rm.sort;

    return data;
}

Josh Johnston

  • Username: Tree2054
  • Joined: Fri Sep 10, 2010 11:41 am
  • Posts: 25
  • IRC: Trii
  • Offline
  • Profile

Re: Server Side Pagination : pages links disappear

Post Posted: Mon Sep 27, 2010 9:45 am
+0-
Also I should note that my JSON response looks like the following with 'records' being my array of data objects

Code:
{
  dir: 'asc',
  pageSize: '10',
  recordsReturned: '10',
  sort: 'someId',
  startIndex: '1',
  totalRecords: '42',
  records: [{/*record here*/}]
}

VS_0511

  • Username: vs0511
  • Joined: Fri May 07, 2010 8:20 am
  • Posts: 51
  • Offline
  • Profile

Re: Server Side Pagination : pages links disappear

Post Posted: Mon Sep 27, 2010 10:01 am
+0-
Thank you : my JSON looks like :
{
records:[ { record1}, {record2} ... ],
"recordsReturned": 100,
"totalRecords": 500,
"startIndex": 0,
"dir": "asc",
"pageSize": 5
}

I am wondering when "handleDataReturnPayload" is called. I tried to put an alert there but it never popped up.

Also, in my JSON document I have 3 sections : columnDef ( I called it meta ), responseSchema and records. In ResponseSchema section I have "metaFields" attribute defined with <key,value> : "totalRecords":"totalRecords". In "records" section I have pagination attributes defined after the actual records.

Still doesn't work. Is there any way to debug it?

Josh Johnston

  • Username: Tree2054
  • Joined: Fri Sep 10, 2010 11:41 am
  • Posts: 25
  • IRC: Trii
  • Offline
  • Profile

Re: Server Side Pagination : pages links disappear

Post Posted: Mon Sep 27, 2010 10:08 am
+0-
Can you show your datasource config? If you don't have your metaFields defined correctly in the responseSchema section they won't be made available inside the handleDataReturnPayload callback.

Posting the whole javascript code, wrapped in code tags would help.

VS_0511

  • Username: vs0511
  • Joined: Fri May 07, 2010 8:20 am
  • Posts: 51
  • Offline
  • Profile

Re: Server Side Pagination : pages links disappear

Post Posted: Mon Sep 27, 2010 10:10 am
+0-
In place of the pages links I have that :

<< first< prevnext >last >> - nothing is clickable.

It seems like the Payload object doesn't have pagination attributes initialized.
  [ 19 posts ] Go to page 1, 2 Next
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum