Server Side Pagination -- buttons disabled

Server Side Pagination -- buttons disabled

toriachttoriacht Posts: 20Questions: 5Answers: 1
edited April 2013 in DataTables 1.9
Hi,

I am using DataTables on front end talking to a Java Server via REST. I can populate the tables etc but I am having difficulty getting pagination working. I am unsure what to set when returning. I have tried a number of different approaches, all failed...The server code below

1. reads in iDisplayStart and iDisplayLength sent from GUI
2. queries DB for all data (ignoring iDisplay values)
3. Selects a subset of results set based on iDisplayStart and iDisplayLength
4. Sets this subset as the return list
5. sets setiTotalDisplayRecords = to the trimmed down list (from start to display length)
6. sets setiTotalRecords = total list returned from DB
7. returns,...


If i return the subset(trimmed list), this is all that's displayed but pagination buttons are disabled
If i return total data, this gets displayed and pagination buttons disabled

Any help much appreciated,
T

[code]
@GET
@Produces("application/json")
public String getRecords(@PathParam("userId") final Long userId, @QueryParam("sEcho") final int sEcho, @QueryParam("iDisplayStart") final int iDisplayStart, @QueryParam("iDisplayLength") final int iDisplayLength ) throws IOException {
logger.info("retreiving records for a customer with a user of id : " + userId);
logger.info("QueryParameters: sEcho: "+sEcho+ " start: "+iDisplayStart+ " length: "+iDisplayLength);

//int ssEcho = sEcho+1;
int displayLength=iDisplayLength;

//final List results = dao.getRecordsForCustomer(userId, iDisplayStart, iDisplayLength);
final List results = dao.getRecordsForCustomer(userId);

logger.info("Total Returned list from database: "+results.size());
if(iDisplayLength

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Are you able to link us to a test page, or use the debugger on your page?

    I think this is part of the problem:

    > aaData.setiTotalDisplayRecords(trimmedResultList.size());

    That's just iDisplayLength is it not? DataTables, if it needed to know the number of records returned it would just do 'data.length', and not require it as a separate parameter. iTotalDisplayRecords, are (from the documentation):

    > Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned in this result set)

    http://datatables.net/usage/server-side

    Allan
  • toriachttoriacht Posts: 20Questions: 5Answers: 1
    Hi Allan,

    Thanks for that..that fixed it.

    Can you explain the difference between iTotalDisplayRecords & iTotalRecords.. i.e. what does 'after filtering' mean?

    I thought "Total records, after filtering " meant "the full DB result MINUS everything you don't want to display".. i.e. everything you have filtered

    Currently I am setting iTotalRecords and iTotalDisplayRecords to the same value.

    Thanks
    T
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > what does 'after filtering' mean?

    Just that - the number of records in the data set, with filtering applied.

    > I thought "Total records, after filtering " meant "the full DB result MINUS everything you don't want to display".. i.e. everything you have filtered

    Sounds correct, but the way I read your code (and since I don't know Java, I'm guessing a bit), it looks like it is taking the size of the filtered AND paged data set, not just the filtered data set.

    It would be very helpful if you could link to a test page so I can see exactly what is happening please: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read

    Allan
This discussion has been closed.