How to print auto serial number in datatable?

How to print auto serial number in datatable?

anovobanovob Posts: 3Questions: 2Answers: 0
edited November 2019 in Free community support

Hello all,

I've added one table and I tried to add an auto increment table row called "serial" for the serial number using the https://legacy.datatables.net/ref#fnRowCallback option, the code goes as:

"fnRowCallback" : function(nRow, aData, iDisplayIndex){
$("td:first", nRow).html(iDisplayIndex +1);
return nRow;
},

The serial number is coming, but the serial number is not showing in print, any one can please help me what to do now?

My Test https://jsfiddle.net/x3nq0zL4/1/

Answers

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    Hi @anovob ,

    You can use orthogonal data for that. Your fiddle was giving me problems so I copied it to here, and it's doing what you want.

    Cheers,

    Colin

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    I just saw your other thread - please don't duplicate threads.

  • AsifAzizAsifAziz Posts: 8Questions: 2Answers: 0
    edited May 2020

    Hi @Colin,

    The link you suggested is working fine but there is an issue in it. Our original list index start from 1 but in print the index start from 0.

    Regards,
    Asif Aziz

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    That just needs a +1 here:

                    return type == 'export' ? meta.row + 1 : data;
    

    See example,

    Colin

This discussion has been closed.