Updating The Number Of Entries Label After A New Search

Updating The Number Of Entries Label After A New Search

tinker1123tinker1123 Posts: 22Questions: 0Answers: 0
edited October 2012 in General
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

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Hi Steve,

    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
  • tinker1123tinker1123 Posts: 22Questions: 0Answers: 0
    Hi 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]
  • jefffan24jefffan24 Posts: 18Questions: 0Answers: 0
    edited October 2012
    How are you returning "sEcho"? In PHP in the array your built to return the data:

    [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.
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    @jeffan24 - Right on, but you should really use `intval` on the _GET parameter otherwise you open yourself to a scripting venerability.

    @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
  • jefffan24jefffan24 Posts: 18Questions: 0Answers: 0
    edited October 2012
    Yeah I forget to add that and I've edited my post so people don't copy that without it.

    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.
  • tinker1123tinker1123 Posts: 22Questions: 0Answers: 0
    @jeffan24

    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
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    > I'm using Java. Do I need to send sEcho, in the JSON without quotes around the value?

    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
  • tinker1123tinker1123 Posts: 22Questions: 0Answers: 0
    Thanks guys. I looked through my code and discovered that the value ( total number of records found from a *filtered* search ) I was using for the variable iTotalDisplayRecords being sent back from the server to DataTables was not being updated. That fixed the problem.
This discussion has been closed.