JSON Data loading with columns

JSON Data loading with columns

rajgummarajgumma Posts: 19Questions: 0Answers: 0
edited December 2012 in DataTables 1.9
Hi,

I want to load the datatables body and header from a JSON string that I get from a Spring Controller thru a Jquery Ajax call

My script looks something like this

[code]
$.ajax({
type : "POST",
url : "/mySite/getconfigdataresults",
datatype : "json",
data : ({
"data" : "test"
}),
success : function(json) {
alert('In Success');
alert('The response is '+json);
$('div#searchResults').hide();
json.bDestroy = true;
$('#MySearch').dataTable(json);
$('div#searchResults').show();
},
error : function(e) {

alert(e);
}
});
[/code]

and my JSON is
[code]
{

"aaData": [
[ "2010-07-27 10:43:08", "..."], [ "2010-06-28 17:54:33", "..."],
[ "2010-06-28 16:09:06", "..."], [ "2010-06-09 19:15:00", "..."]
] ,

"aaSorting": [
[ 1, "desc" ]
],

"aoColumns": [
{ "sTitle": "Title1" },
{ "sTitle": "Title2" }
]

}
[/code]

This way of achieving it was an inspiration from a previous(currently closed ) post
http://datatables.net/forums/discussion/2529/column-definition-via-json-array-ajax/p1

The problem is i am getting a script error @ line 6542 char 11, code at that place shows

[code]/* Set the current sorting index based on aoColumns.asSorting */
for ( j=0, jLen=oColumn.asSorting.length ; j

Replies

  • rajgummarajgumma Posts: 19Questions: 0Answers: 0
    I have even checked the whether my dataTables.js is the right one, it is same as the one at http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.2/jquery.dataTables.js
  • rajgummarajgumma Posts: 19Questions: 0Answers: 0
    Hi

    I am in a very needy situation for whether to go with DataTables plugin or not. Any help with the above error is a boon
  • rajgummarajgumma Posts: 19Questions: 0Answers: 0
    Hi,

    I tried to take out the JSON out of it and did the following

    [code]
    $('#MySearch').dataTable({
    "bProcessing" : true,
    "bDestroy" : true,
    "bAutoWidth" : true,
    "sScrollY" : "200",
    "sScrollX" : "100%",
    "bScrollCollapse" : false,
    "bSort" : true,
    "aLengthMenu": [[10, 15, 25, -1], [10, 15, 25, "All"]],
    "sPaginationType" : "full_numbers",

    "aaData": [
    /* Reduced data set */
    [ "Trident", "Internet Explorer 4.0", "Win 95+", 4, "X" ],
    [ "Trident", "Internet Explorer 5.0", "Win 95+", 5, "C" ],
    [ "Trident", "Internet Explorer 5.5", "Win 95+", 5.5, "A" ],
    [ "Trident", "Internet Explorer 6.0", "Win 98+", 6, "A" ],
    [ "Trident", "Internet Explorer 7.0", "Win XP SP2+", 7, "A" ],
    [ "Gecko", "Firefox 1.5", "Win 98+ / OSX.2+", 1.8, "A" ],
    [ "Gecko", "Firefox 2", "Win 98+ / OSX.2+", 1.8, "A" ],
    [ "Gecko", "Firefox 3", "Win 2k+ / OSX.3+", 1.9, "A" ],
    [ "Webkit", "Safari 1.2", "OSX.3", 125.5, "A" ],
    [ "Webkit", "Safari 1.3", "OSX.3", 312.8, "A" ],
    [ "Webkit", "Safari 2.0", "OSX.4+", 419.3, "A" ],
    [ "Webkit", "Safari 3.0", "OSX.4+", 522.1, "A" ]
    ],
    "aoColumns": [
    { "sTitle": "Engine" },
    { "sTitle": "Browser" },
    { "sTitle": "Platform" },
    { "sTitle": "Version", "sClass": "center" },
    { "sTitle": "Grade", "sClass": "center" }
    ]

    });
    [/code]

    and yet i get the same error mentioned above
  • allanallan Posts: 62,338Questions: 1Answers: 10,228 Site admin
    Please link to a test case so we can offer help: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read

    The basic idea looks like it should work just fine, so we would need a test case to be able to offer any help.

    Allan
  • rajgummarajgumma Posts: 19Questions: 0Answers: 0
    http://live.datatables.net/iguvuc/edit#javascript,html,live

    The code works fine on datatables nightly and doesn't work on 1.9.1 version. Couldn't find the 1.9.2 version on the ui.

    Thanks in advance,
    Raj
  • rajgummarajgumma Posts: 19Questions: 0Answers: 0
    edited December 2012
    Hi Allan,
    Finally could get it on jsFiddle

    http://jsfiddle.net/UnaDU/ on jsFiddle
    with datatables plugin referring from
    http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.2/jquery.dataTables.js

    The table is rendered properly in the fiddle however it is throwing an error in my code at the location mentioned in my earlier comments . Its really strange that this works fine in fiddle but not in my code.

    Any pointers on what i might be missing or how you want me to debug the script?
This discussion has been closed.