Load datatable with JSON data gives an error Requested unknown parameter '0' from the data source f

Load datatable with JSON data gives an error Requested unknown parameter '0' from the data source f

ashviniashvini Posts: 2Questions: 0Answers: 0
edited August 2012 in DataTables 1.9
I have been trying to load json data into datatable but somehow it fails and displays " Requested unknown parameter '0' from the data source for row 0" error and no data is populated in the table.
I referred all possible sources available online but i am still not able to get around it .
I am a complete newbie in jquery programming and using handlebar for templating.
[code]
(function( $ ){

$.fn.managecontractsview = function() {

return this.each(function() {

objManageContract = $(this)
//use jQuery ".live" function to bind to events from controller and other views


function loadJsonData(){


commandFactory.create({'type': 'getContracts',
'params': {},
'successhandler': function(reply){
//trigger event to notify any views listening for contracts
$.event.trigger('loadContractList',reply.response );
},
'errorhandler': function(reply) {
alert('Error retrieving Contracts, error status of: ' + reply.status.text);
$.event.trigger('loadContractListError', 'Error retrieving contract list, error status of: ' + reply.status.text);
}}).execute();
}
objManageContract.live(
{
loadSearchContract: function(event, contract) {

templ = Handlebars.templates["manageContracts"];
objManageContract.html(templ(contract));
// load list on search input
$("#contract-search-input").live('keyup',function(event){
if(event.keyCode == 13){
alert("in click of search");
loadJsonData();
}
});
}
loadContractList: function(event, contract){
var oTable = $('#contract-list').dataTable({
"bJQueryUI": true,
"bPaginate": false,
"bLengthChange": false,
"bFilter": false,
"bSort": false,
"bInfo": false,
"bAutoWidth": false,
"bRetrieve": true,
"aaData":[contract],
/* "aaData": [[ "Aetna","12345"],
["BCBS Society", "78686"],
[ "Wallmark", "989083"/01/2012" ]],*/
"aoColumns": [
{ "sTitle": "name" },
{ "sTitle": "alias" }

]

});

[/code]

If I use a static data array (the commented one), it works fine.
So it makes me think the way i m getting the json data is errorneous.
I will appreciate if i can get any help in this matter.I have been struggling on this for past couple of days.
I even tried converting the json object into an javascript array , but even that did not work.
Thank you for helping.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    http://datatables.net/faqs#unknown_parameter

    Can you give us a debugger trace please?

    Allan
  • broadway69broadway69 Posts: 2Questions: 0Answers: 0
    I'm a total noob when it comes to Data Tables but ran into the problem repeatedly over the weekend. The way I solved it was by adding mData info to the "aoColumns" table which I think is required if your building both your thead and tbody with code. Hope it helps.

    [code]
    "aoColumns" : [
    { "sTitle" : "Formal Name", "mData" : "column_key_name"},
    { "sTitle" : "Formal Title", "mData" : "column_key_title"},

    [/code]
  • ashviniashvini Posts: 2Questions: 0Answers: 0
    The problem got solved after i converted the json object to javscript array and now it is working fine.
This discussion has been closed.