Index column with Ajax

Index column with Ajax

ejzhangejzhang Posts: 2Questions: 1Answers: 0

I modify the ajax example to add index column, like bellow. But the index column overwrited by value of data property. How i to do correctly? Thanks very much!
http://www.datatables.net/examples/ajax/objects.html
var t = $(document).ready(function() {
$('#example').DataTable( {
"ajax": "data/objects.txt",
"columns": [
{ "data": null },
{ "data": "name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "extn" },
{ "data": "start_date" },
{ "data": "salary" }
]
} );
} );
t.on( 'order.dt search.dt', function () {
t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
cell.innerHTML = i+1;
} );
} ).draw();

Answers

  • ejzhangejzhang Posts: 2Questions: 1Answers: 0
    var t = $(document).ready(function() {
        $('#example').DataTable( {
            "ajax": "data/objects.txt",
            "columns": [
                { "data": null },
                { "data": "name" },
                { "data": "position" },
                { "data": "office" },
                { "data": "extn" },
                { "data": "start_date" },
                { "data": "salary" }
            ]
        } );
    } );
    t.on( 'order.dt search.dt', function () {
        t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
            cell.innerHTML = i+1;
        } );
    } ).draw();
    
This discussion has been closed.