Counter Column with JSON Example?
Counter Column with JSON Example?
There's a Counter Column example on the site.
http://www.datatables.net/examples/api/counter_column.html
However, when I change the data source from HTML table in the example to JSON, since each JSON record is an array with three items, like the following, the "column number mismatch" error occurred when bound to a four-column data table configuration:
[code]
var json = [
[100023, 'Jack', 'M'], [100232, 'Rose', 'F']
];
...
"aoColumns": [
{ "bSortable": false }, // for counter column
null, // for ID number column
null, // for Name column
null // for Gender column
]
[/code]
How can I work around this?
http://www.datatables.net/examples/api/counter_column.html
However, when I change the data source from HTML table in the example to JSON, since each JSON record is an array with three items, like the following, the "column number mismatch" error occurred when bound to a four-column data table configuration:
[code]
var json = [
[100023, 'Jack', 'M'], [100232, 'Rose', 'F']
];
...
"aoColumns": [
{ "bSortable": false }, // for counter column
null, // for ID number column
null, // for Name column
null // for Gender column
]
[/code]
How can I work around this?
This discussion has been closed.
Replies
Allan
I added the following line before calling the data table constructor function:
[code]
$.each(json, function(i, n) { n.unshift(0); });
[/code]