iDeferLoading and paging with initial server-side filtering?

iDeferLoading and paging with initial server-side filtering?

larryllarryl Posts: 6Questions: 0Answers: 0
edited December 2011 in DataTables 1.8
Hi -

Short version: Is there any way to set the equivalent of both iTotalRecords and iTotalDisplayRecords when using iDeferLoading?

I'm using server-side processing. Assume my page size is 25 and there are 100 total records...

For my initial table draw I send the first 25 rows, and set iDeferLoading = 100. Then on subsequest AJAX requests I send iTotalRecords = 100 and iTotalDisplayRecords = (some number between 0 and 100 depending on filtering). When I type into the filter box I see correct page info, e.g. "Showing 1 to 25 of 57 rows (filtered from 100 total rows)". So far so good.

However, in some cases I need to apply some initial filter to the data before the table is drawn for the first time. Assuming there are 57 items after initial filtering, for the initial table draw I still send the first 25 rows but then:

1) If I set iDeferLoading = 100, then the first page incorrectly says "Showing 1 to 25 of 100 rows".

2) If I set iDeferLoading = 57, then the first page says "Showing 1 to 25 of 57 rows", which is correct but missing the "(filtered from 100 total rows)" part.

In either case, clicking to the next page shows the correct "Showing 26 to 50 of 57 rows (filtered from 100 total rows)".

So, when using iDeferLoading, is there any way to specify both the total number of rows and the number of rows to display?


Thanks!
Larry

Replies

  • jmonty_mejmonty_me Posts: 1Questions: 0Answers: 0
    I have a similar desire using server-side data. While it's possible to tell DataTables the initial filter string, initial sort column & sort direction, etc. there doesn't seem to be a way to let DataTables know that I've already provided the filtered data on the initial page and all it has to do is reflect the (x of y) type of information. My current solution is to not include any initial table data and to just to not set iDeferLoading. I still get the final page that I want but there is the inherent delay caused by having to let the backend processing take care of that first page of data. It seems like having just a few more parameters on setup would make server-side processing much more flexible.
  • allanallan Posts: 61,824Questions: 1Answers: 10,129 Site admin
    Hi,

    Sorry I missed the original post Larry.

    Yes, this is a limitation in the current implementation of iDeferLoading. What I've done is to allow iDeferLoading to be given as an array, in addition to its current integer form. When given as an array the first element is the number of records available after filtering and the second element is the number of records without filtering.

    Thus you would do something like:

    [code]
    $('#example').dataTable( {
    "bServerSide": true,
    "sAjaxSource": "scripts/server_processing.php",
    "iDeferLoading": [ 57, 100 ],
    "oSearch": {
    "sSearch": "my_filter"
    }
    } );
    [/code]

    This is now available in the 1.9.1.dev nightly ( http://datatables.net/download ) and will be included in the 1.9.1 release (which should be quite soon).

    Allan
  • larryllarryl Posts: 6Questions: 0Answers: 0
    Hi Allan -

    I just saw a mention of this in the 1.9.1.dev notes, very glad to see this enhancment go in.

    Thanks very much!
    Larry
This discussion has been closed.