Displaying table using AjaxSource, DataTables warning: requested unknown parameter '0' from the data

Displaying table using AjaxSource, DataTables warning: requested unknown parameter '0' from the data

kulkarni_ashkulkarni_ash Posts: 35Questions: 8Answers: 0
edited December 2011 in DataTables 1.8
I downloaded datatable and added it to my SpringMVC project, and i created following in my jsp and java script and i get the following error
[code]datatables warning request unknow parameter '0' from the data source for row 0[/code]
[code]

$(document).ready(function() {
$('#airports').dataTable({
"bSort": false,
"sPaginationType": "full_numbers" ,
"bProcessing": true,
"sAjaxSource": 'displayAirportAjax.spring'


}
);
} );




Select
Code
Name
City
State
Country
Type
Is Tauck Provided
Is City Default





[/code]

The JSON array i return is as below

[code]
aaData= [{"AIRPORTCD":"","AIRPORTID":0,"AIRPORTNAME":"","CITYCD":"","CITYCOUNTRYCD":"","CITYNAME":"","COUNTRYCD":"","COUNTRYNAME":"","EFFECTIVEDATE":null,"ISCITYDEFAULT":"","ISOA2":"","ISTAUCKPROVIDED":"","RETIREDATE":null,"STATECD":"","STATENAME":"","TRANSPORTATIONTYPECD":""}]
[/code]

Replies

  • allanallan Posts: 61,869Questions: 1Answers: 10,137 Site admin
    You need to use mDataProp to tell DataTables what JSON property belongs to each column (otherwise how is it to know that AIRPORTCD is column 5 (or whatever) :-). There is a blog post describing mDataProp here: http://datatables.net/blog/Extended_data_source_options_with_DataTables

    Allan
  • kulkarni_ashkulkarni_ash Posts: 35Questions: 8Answers: 0
    edited December 2011
    Allan
    Thanks i added the following code as below
    [code]
    "aoColumns": [
    { "mDataProp": "airportcd" }

    ]
    [/code] and it worked great,
    Once more question, i want to add a check box for first columns, can you point towards some example to do so
  • allanallan Posts: 61,869Questions: 1Answers: 10,137 Site admin
    There are three basic ways of doing it:

    1. Simply include the checkbox HTML in your JSON return and use that for the column
    2. Use fnRender for that column to create the needed HTML
    3. Use sDefaultContent to create the needed HTML (although with this method you can't set a unique ID/Name for the checkbox, which you would presumably want).

    Allan
  • kulkarni_ashkulkarni_ash Posts: 35Questions: 8Answers: 0
    Allan
    Thanks for the information, i converted by definition as below and it is working fine, I have one more question

    My resultset returns about 3500 rows, and so rendering of table takes little time, is there some parameter which can speed up rendering of table? this is a big issue since users get frustrated when application loads slowly, i really dont want to implement some server side code to load 500 at a time or some thing, is there any parameter in Datatables to help

    My new code in java script is as below, and works very well expect for the speed
    [code]
    $(document).ready(function() {
    $('#airports').dataTable({
    "bSort": false,
    "sPaginationType": "full_numbers" ,
    "bProcessing": true,
    "sAjaxSource": 'displayAirportAjax.spring',
    "aoColumns": [

    {
    "fnRender": function ( oObj ) {

    return '';
    }
    }
    ,
    {
    "fnRender": function ( oObj ) {
    var text = "" + oObj.aData.airportcd + "";
    return text;
    }

    },
    { "mDataProp": "airportname" },
    { "mDataProp": "cityname" },
    { "mDataProp": "statename" },
    { "mDataProp": "countryname" },
    { "mDataProp": "transportationtypecd" },
    { "mDataProp": "istauckprovided" },
    { "mDataProp": "iscitydefault" }
    ]


    }
    );
    } );
    [/code]
  • allanallan Posts: 61,869Questions: 1Answers: 10,137 Site admin
    Yes - enable deferred rendering: bDeferRender - you'll get a large speed boost for this type of table.

    Allan
  • kulkarni_ashkulkarni_ash Posts: 35Questions: 8Answers: 0
    Hi enabled bDeferRender:true to my settings above, but i dont see any big difference, without this parameter it takes about 15 seconds for the page to render, and with this parameter it takes about 10 seconds, and off course this is in IE 8, in chrome the time is about 4 seconds less
  • allanallan Posts: 61,869Questions: 1Answers: 10,137 Site admin
    How much of that time is it waiting for the Ajax response (the Chrome dev tools will tell you). A link would be really useful. If Chrome is taking 6 seconds to render 3500 rows, then I would imagine the Ajax response is taking up a fair amount of those 6 seconds.

    Allan
  • kulkarni_ashkulkarni_ash Posts: 35Questions: 8Answers: 0
    This is working fast now, dont know how
This discussion has been closed.