Counter Column with JSON Example?

Counter Column with JSON Example?

sd_zuosd_zuo Posts: 78Questions: 1Answers: 0
edited July 2010 in General
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?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Try putting in an empty string as the first element in the JSON subarrays. Those array lengths _must_ match your aoColumns length.

    Allan
  • sd_zuosd_zuo Posts: 78Questions: 1Answers: 0
    edited July 2010
    Well, it seems that there's no way to achieve this without modifying the JSON data.
    I added the following line before calling the data table constructor function:
    [code]
    $.each(json, function(i, n) { n.unshift(0); });
    [/code]
This discussion has been closed.