Increment column number for each row by 1

Increment column number for each row by 1

orik3ll0orik3ll0 Posts: 36Questions: 12Answers: 2
edited August 2019 in General

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

  • colincolin Posts: 10,137Questions: 0Answers: 1,698

    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

  • kthorngrenkthorngren Posts: 11,025Questions: 25Answers: 2,524

    See if this example does what you want:
    https://datatables.net/examples/api/counter_columns.html

    Kevin

  • orik3ll0orik3ll0 Posts: 36Questions: 12Answers: 2

    @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

  • orik3ll0orik3ll0 Posts: 36Questions: 12Answers: 2

    here is js code in fiddle
    https://jsfiddle.net/Orik3ll0/vdqtx764/3/

  • colincolin Posts: 10,137Questions: 0Answers: 1,698

    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

  • orik3ll0orik3ll0 Posts: 36Questions: 12Answers: 2

    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; }); });

Sign In or Register to comment.