Increment column number for each row by 1
Increment column number for each row by 1
Hello,
I uje ajax to fill my table. I want to set number for each row, 1,2,3,4,5.... but can not increment. For example here is a code of rebder
{
targets : [0],
render: function ( data, type, row, meta ) {
return data.meta+1;
}
},
Replies
Hi @orik3ll0 ,
That looks about right. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
See if this example does what you want:
https://datatables.net/examples/api/counter_columns.html
Kevin
@colin Hi, Thank you for the response. I will do it
@kthorngren Thank you for reply. Yes, it works, but if i jump from any page to last one, let say for example from 1 page to 63: it shows me 1-10 and on 64 page shows 11-20, but should show 631-640. That exactly what i need to fix
here is js code in fiddle
https://jsfiddle.net/Orik3ll0/vdqtx764/3/
Hi @orik3ll0 ,
That fiddle doesn't run. But I think you just need to use
createdRow
to add an incrementing number to each row.Cheers,
Colin
I solved problem with page.info and made changes for server-side case. Here is the 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;
});
});
I've had to do decrement column, it was a pain. There were no topics about that, I want to post code here. This is not an aswer to question but maybe it will help someone.
It was nearly impossible to get current_page from api, because I needed page number in "columns" property. I could get it on some other places but at first in "columns" it would not be defined, so I wrote this:
`
In columns:
select[name='job_sheet-tbl_length'] - dropdown, where you choose how many rows have to be displayed
In summary, I get entire row count, then subtract (current_page_number * records_per_page) - (column_index) to get descending order.
If anyone knows better approach, please post it.
p.s. I am using ssp for this.