Need a counter column for a datatable with server side processing

3.7k Views Asked by At

I need to add one extra column to the datatable. This column will have incrementing serial no like 1, 2, 3, 4 etc...

I found this example, but this is not working for server side processing and I want searching-sorting working(if possible) which is also not here.

https://datatables.net/examples/api/counter_columns.html

Notes:

1) Datatable uses server side processing.

2) Sorting and searching should work on that counter column. (if possible)

3) Would be good, if I can achieve it completely on the client side using js. I don't want to make any code at server side for this(if possible).

4) Pagination should update counter no serially means if the previous page has last counter no 15, then next page should start with counter 16.

By the way I also checked this:

"Column Index" on a server-side processed DataTable

But accepted answer of this question violates my 4th requirement.

Any help would be appreciated.

Thanks,

Parth Vora

2

There are 2 best solutions below

0
On

If anyone still has this problem, I solved it with draw event listener and DataTable's page.info() method. My code:

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

IT WILL WORK FINE "Thank You Brother Your Code usefull..Mansur Anorboev "