Server Side - Stuck

Server Side - Stuck

bpeterson76bpeterson76 Posts: 11Questions: 0Answers: 0
edited July 2010 in General
All,

Wondering if someone could help. I've been using DataTables quite some time both via dom maniuplation and JSON code. However, two of our larger resultsets are still running too slow, so I'm attempting to convert them over to client-side prospecting.

The following is my code:

AJAX page output (truncated for clarity purposes):

[code]
{"sEcho": "0", "iTotalRecords": "1788", "iTotalDisplayRecords": "1788", "aaData":[["", "", "First", "Last", "company ", "address", "city", "state", ""] ,["", "", "first1", "last1", "company1", "address1", "city1", "state1", "email1"] ]}
[/code]

Jquery Initialization:

[code]
jQuery('#prospectList').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/web/prospect/ajax",
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bAutoWidth": false,
"bFilter":true,
"bLengthChange": true,
"bPaginate": true,
"bSort": true,
"iDisplayLength": 10,
"bInfo": true,
"aoColumns": [
{ "sTitle": "Action" },
{ "sTitle": "First Name" },
{ "sTitle": "Last Name" },
{ "sTitle": "Company" },
{ "sTitle": "Street"},
{ "sTitle": "City" },
{ "sTitle": "State" },
{ "sTitle": "Email" }
]
})
[/code]

Replies

  • gutzoftergutzofter Posts: 58Questions: 0Answers: 0
    here is your json:
    [code]
    {
    "sEcho": "0",
    "iTotalRecords": "1788",
    "iTotalDisplayRecords": "1788",
    "aaData": [
    //partial json
    [/code]
    here is what mine looks like:
    [code]
    {
    "sEcho": 1,
    "iTotalRecords": 372,
    "iTotalDisplayRecords": 372,
    "aaData": [
    //partial json
    [/code]

    it appears that your dataTables variable values are in strings, except for aaData.
  • bpeterson76bpeterson76 Posts: 11Questions: 0Answers: 0
    Gutzofter, indeed, however I've tried that before and just now with no resolution of the issue. I still get a table that has a header but no data displayed and no errors of any kind generated.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    With an sEcho value of 0, I would guess that you are just printing out 0 rather than echoing back what the 'sEcho' HTTP variable is (since DataTables starts it off at 1) - remember to cast it as an int (or parse it or whatever your server-side language uses).

    gutzofter is also correct in that DataTables is expecting numbers for the first three parameters there, rather than strings.

    Allan
  • gutzoftergutzofter Posts: 58Questions: 0Answers: 0
    @allan - I've seen several people generate this json type data before, I guess creating a test json to send without actually using a database.

    Is it possible to set it up that if you use sEcho from the server with a value of -1 that dataTables will display it no matter what sequence dataTables is at?
  • bpeterson76bpeterson76 Posts: 11Questions: 0Answers: 0
    Guys, thanks for the help. Indeed, when you pass an sEcho of zero it'll fail every time without any sort of error. That, combined with not realizing the aoColumns "gotcha" right away slowed me down quite a bit and would be a great addition to the base documentation. I appreciate your quick responses!
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    @gutzofter: It is possible to do what you suggest, but it will produce extremely hard to pin point timing errors, which is why the echo variable is there at all. As such I would be reluctant to do that.

    @bpeterson76: The use of sEcho is noted on this page, which details the 'protocol' used for client/server comms: http://datatables.net/usage/server-side . Also in all of the example code, the echo variable is returned as required. Good to hear you got it working in the end :-)

    Allan
  • gutzoftergutzofter Posts: 58Questions: 0Answers: 0
    @allan - This would be for integration testing purposes. Maybe have the label say "Testing synch header received"
This discussion has been closed.