DataTable: Json Data is with key and value.

DataTable: Json Data is with key and value.

ayush199407ayush199407 Posts: 1Questions: 1Answers: 0

var dataSet1 ={
"data": [
{"id":1,"gender":"M","first":"John","last":"Smith","city":"Seattle, WA","status":"Active"},
{"id":2,"gender":"F","first":"Kelly","last":"Ruth","city":"Dallas, TX","status":"Active"},
{"id":3,"gender":"M","first":"Jeff","last":"Stevenson","city":"Washington, D.C.","status":"Active"},
{"id":4,"gender":"F","first":"Jennifer","last":"Gill","city":"Seattle, WA","status":"Active"}
}
};

I have json with above type of data.

To intilize the row data i have tried
1.
$('#Database').DataTable( {
ajax: "data.json",
columns: [
{ title: "id" },
{ title: "gender" },
{ title: "first" },
{ title: "last." },
{ title: "city" },
{ title: "status" }
]
} );

2.
$('#Database').DataTable( {
ajax: dataset1,
columns: [
{ title: "id" },
{ title: "gender" },
{ title: "first" },
{ title: "last." },
{ title: "city" },
{ title: "status" }
]
} )
3.
even i copied the dataset1 in data.json file which are in same folder but its not working.

Can Anyone help me what i am missing.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Take a look at this live example here . I've quickly knocked out how it should look with local data. If you look at how the columns are defined, and the expected data format, that should get you going in the right direction.

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Yes, just to elaborate a little on what Colin has said - if you have data already use data to tell DataTables what the data is. ajax is used to configure the Ajax options.

    Allan

This discussion has been closed.