jquery - Sending JSON Objects in DataTables from javascript -
i trying populate datatable json object getting following error:
datatables warning: table id=filteredalertstable - requested unknown parameter 'messageid' row 0. more information error, please see http://datatables.net/tn/4
here code:
var dataset = '${data}'; $('#filteredalertstable').datatable( { "bprocessing": true, "aadata": dataset, "aocolumns": [ { "mdata": "messageid" }, { "mdata": "host" }, { "mdata": "creationtime" }, { "mdata": "resolvedtime" }, { "mdata": "severity" }, { "mdata": "alerttext" } ] } );
i getting dataset javascript variable, tried passing following,
[{ "severity": "severity", "creationtime": "creationtime", "resolvedtime": "resolvedtime", "appname": "appname", "host": "host", "messageid": "messageid", "alerttext": "alerttext" }, { "severity": "severity1", "creationtime": "creationtime1", "resolvedtime": "resolvedtime1", "appname": "appname1", "host": "host1", "messageid": "messageid1", "alerttext": "alerttext1" }]
and
{ "mdata": [{ "severity": "severity", "creationtime": "creationtime", "resolvedtime": "resolvedtime", "appname": "appname", "host": "host", "messageid": "messageid", "alerttext": "alerttext" }, { "severity": "severity1", "creationtime": "creationtime1", "resolvedtime": "resolvedtime1", "appname": "appname1", "host": "host1", "messageid": "messageid1", "alerttext": "alerttext1" }] }
i have gone thought this question still can't figure out what's wrong
here html code.
<table id="filteredalertstable" class="table table-striped table-bordered "> <thead> <tr> <th>message id</th> <th>host</th> <th>creation time</th> <th>resolved time</th> <th>severity</th> <th>alert text</th> </tr> </thead> <tbody> </tbody> </table>
it because dataset
string. caused '${data}'
datatable looks :
var dataset = '[{ "severity": "severity", "creationtime": "creationtime", "resolvedtime": "resolvedtime", "appname": "appname", "host": "host", "messageid": "messageid", "alerttext": "alerttext"},{ "severity": "severity1", "creationtime": "creationtime1", "resolvedtime": "resolvedtime1", "appname": "appname1", "host": "host1", "messageid": "messageid1", "alerttext": "alerttext1"}]';
as json works right away -> http://jsfiddle.net/q78tu48q/
so make sure string is in json format :
$('#filteredalertstable').datatable( { "bprocessing": true, "aadata": json.parse(dataset), "aocolumns": [ { "mdata": "messageid" }, { "mdata": "host" }, { "mdata": "creationtime" }, { "mdata": "resolvedtime" }, { "mdata": "severity" }, { "mdata": "alerttext" } ] } );
demo -> http://jsfiddle.net/u76blpa3/
Comments
Post a Comment