Updating The Number Of Entries Label After A New Search
Updating The Number Of Entries Label After A New Search
tinker1123
Posts: 22Questions: 0Answers: 0
Datatables prints out a report of the number of records found in a statement like this under the table:
"Showing 1 to 10 of 12 entries"
This doesn't update if someone runs a new search in the datatables search box( at least not for me, I'm doing server side processing )
Is there an option for this?
If not, I'm guessing I could capture the even of the search box changing, but any idea how I would get the new number of entries found to update the "Showing blah blah blah" statement?
Thanks much in advance
Steve
"Showing 1 to 10 of 12 entries"
This doesn't update if someone runs a new search in the datatables search box( at least not for me, I'm doing server side processing )
Is there an option for this?
If not, I'm guessing I could capture the even of the search box changing, but any idea how I would get the new number of entries found to update the "Showing blah blah blah" statement?
Thanks much in advance
Steve
This discussion has been closed.
Replies
DataTables will update the information element on every draw. For example try filtering in this example: http://datatables.net/release-datatables/examples/data_sources/server_side.html .
So I'd guess that it isn't drawing, and that's usually because sEcho isn't being returned correctly for the server-side processing.
Allan
It is my understanding that the sEcho value sent back from the server has the same value as the sEcho sent to the server. Is my understanding correct?
I verified that this is the case in my logs.
I also copied an example of the JSON sent back to DataTables in my application. Does anything look off with the sEcho?
[code]
{
"sEcho" : "5",
"iTotalRecords" : 168,
"iTotalDisplayRecords" : 168,
"aaData" : [ {
"person_id" : "999888",
"fullname" : "Smith, Amber",
"email_address" : "amber.smith@acme.com",
"current_phone_number" : "301-867-5309",
"org_title" : "Coyte Managment",
"office" : "First Aide",
"position_title" : "Emergency Veternarian"
} ]
}
[/code]
[code]
$data = array('sEcho' => intval($_GET['sEcho']));
[/code]
You can't get it wrong doing that.
Unless your displaying the same amount of data that is in your table (no pagination), iTotalRecords should not be the same iTotalDisplayRecords, iTotalDisplayRecords should be the number of rows on the page.
@tinker1123 - That looks valid to me. We'd need a link to your page to be able to offer an extra help I think.
Allan
I've got snippets saved in sublime that I've gotten so used to using, when I answer questions like this I forget to add them! Really need to get out of that habit.
I'm using Java. Do I need to send sEcho, in the JSON without quotes around the value?
I'm a bit confused about what you wrote about iTotalRecords verus iTotalDisplayRecords.
Lets say that once someone lands on a web page with DataTables. The initial search yielded 30 records. That would be iTotalRecords, correct?
How would I know what iTotalDisplayRecords is on the server side? My user could choose to display 10, 50 or 100 records depending what s/he chooses from the DataTable drop down list.
Thanks munch in advance for the help
Steve
Yes. I assume you are using some kind of json encoder - just set the value.
> I'm a bit confused about what you wrote about iTotalRecords verus iTotalDisplayRecords.
Have you read the documentation: http://datatables.net/usage/server-side ?
> iTotalRecords - Total records, before filtering (i.e. the total number of records in the database)
> iTotalDisplayRecords- 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)
So you need to calculate them from your data set. Are you working with > 50'000 rows? If not, then client-side processing is much easier to implement...
Allan