Skip to content

Get number of a table row. #36

@AndreCabrera

Description

@AndreCabrera

Hi,

I have a datatable in my project and i can't display the number of row in the first column of my table; how to get the number (position) of any row?

here's my code:

$('#myTable').datatable({
    data: json,
    identify: 'field1',
    lineFormat: function (id, data) {
    var tr = $('<tr></tr>') ;
	// First <td> element, here display number of row.
        tr.append('<td></td>') ;
        tr.append('<td>'+data['field1']+'</td>') ;
        tr.append('<td>'+data['field2']+'</td>') ;
        tr.append('<td>'+data['field3']+'</td>') ;
        return tr ;
     }
 });

Consider: when delete rows using $('#myTable').datatable('delete', id); or add new rows $('#myTable').datatable('insert', json); the numbers of table rows update automatically, is there a way to do this ?.

thanks.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions