Incorrect results with server-side data

Incorrect results with server-side data

rman326rman326 Posts: 2Questions: 0Answers: 0
edited January 2011 in General
I've been fighting with this the past few days. I have the following table on a page:

[code]



Customer
Dwelling
Visit Date
Actions




Loading data from server



[/code]

With this initializing the table:
[code]
$("#openVisits").dataTable(
{
"sAjaxSource": "./opentable"
});
[/code]

That url returns the following JSON:
[code]
{
"iTotalRecords": 42,
"iTotalDisplayRecords": 42,
"sColumns": [
"1",
"2",
"3",
"4"
],
"aaData": [
[
"16-1",
"16-2",
"16-3",
"16-4"
],
[
"46-1",
"46-2",
"46-3",
"46-4"
],
[
"62-1",
"62-2",
"62-3",
"62-4"
],
[
"18-1",
"18-2",
"18-3",
"18-4"
],
[
"68-1",
"68-2",
"68-3",
"68-4"
],
[
"35-1",
"35-2",
"35-3",
"35-4"
],
[
"56-1",
"56-2",
"56-3",
"56-4"
],
[
"82-1",
"82-2",
"82-3",
"82-4"
],
[
"6-1",
"6-2",
"6-3",
"6-4"
],
[
"8-1",
"8-2",
"8-3",
"8-4"
]
],
"sEcho": null
}
[/code]

There's a handful of issues I'm experiencing. The first is the table shows "Showing 1 to 10 of 10 entries" in its status line, which is incorrect. But from what I've encountered, the iTotalRecords and iTotalDisplayRecords values are set correctly.

The other issue, though this might stem from the above issue, is no further AJAX calls are made, for sorting, changing the displayed records, searching, etc. I could see this being from the table thinking that there's only 10 records.

Anyone have any thoughts on what could be wrong?

Replies

  • allanallan Posts: 63,201Questions: 1Answers: 10,414 Site admin
    A couple of things:

    1. You haven't enabled server-side processing in the DataTables initialisation - so it's only going to be looking at aaData - which is why you are only getting 10 rows. See http://datatables.net/usage/server-side - and in particular bServerSide.

    2. sEcho is null - but that might just be cause DataTables isn't sending any parameters (since server-side processing isn't enabled).

    3. sColumns should be a comma separated string, rather than an array of strings (although sColumns won't do anything since you haven't set up column names in the initialisation so that could be dropped)

    4. How is the server-side script working with out getting any parameters from DataTables (like iDisplayLength, and iStart etc)!? DataTables won't send these parameters without server-side processing being enabled :-)

    So first step - enable server-side processing and the rest will likely fall into place.

    Allan
  • rman326rman326 Posts: 2Questions: 0Answers: 0
    The ServerSide parameter was there, it was just victim of my simplification for posting here. However, I did just notice the actual issue: I had sServerSide instead of bServerSide in the initializer. It's amazing what one little character can do, and how long I went back and forth comparing my code to the examples. Works quite well now.

    sEcho and the iDisplayLength and all that were null-able parameters (I'm using ASP.Net MVC), and a simple null check replaced them with sensible defaults if they weren't provider. However, this is moot. But I just thought I'd answer that question.

    Thanks.
This discussion has been closed.