Index column in datatables

Asked

Viewed 122 times

0

When I did not load the data dynamically into the table I used this way to create the index column: https://datatables.net/examples/api/counter_columns.html

 t.on( 'order.dt search.dt', function () {
    t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
        cell.innerHTML = i+1;
    } );
} ).draw();

Example: https://jsfiddle.net/umn75pj1/

However, now that I am loading the dynamically server-side table does not work properly. It is always from 1 to 5. If I increase results per page add the index.

I tried to use it that way and I didn’t succeed either:

t.on( 'order.dt search.dt', function () {
t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
    cell.innerHTML = i+1;
    t.cell(cell).invalidate('dom');
} ); } ).draw();

I’m studying jquery, Laravel and the server-side usage of datatables yet. I don’t know how to solve this.

1 answer

0


Make it work.

For those who go through the same problem that I solved using page.info(), making the product the value of the quantity of items to be displayed and the number of the current page: page.info(). page * page.info(). length.

tabela.on('draw.dt', function() {
    tabela.column(0, { search: 'applied', order: 'applied'}).nodes().each(function(cell, i) {
        cell.innerHTML = tabela.page.info().page * tabela.page.info().length + i + 1;  
    });
}).draw();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.