iDeferLoading and paging with initial server-side filtering?
iDeferLoading and paging with initial server-side filtering?
larryl
Posts: 6Questions: 0Answers: 0
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
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
This discussion has been closed.
Replies
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
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