Resume running count of serial number (index column) on page change in datatable

Resume running count of serial number (index column) on page change in datatable

modismodis Posts: 6Questions: 3Answers: 0
edited March 2017 in Free community support

Hello All,

I am a bit new to datatable. I am using datatable in my .cshtml page to show records in which i am generating index number for each serial number column records using following code.

SecondarySellerTable = $('#SecondarySellerTable').DataTable({
    "processing": true,
    "stateSave": true,
    "ajax": {
        "url": "@Url.Action("GetSecondarySellers", "SecondarySellers")",
        "type": "POST",
        "complete": function () {
            $('#imgLoadingSecondarySeller').css("display", "none")
        }
    },
    "columns": [
    { "data": null },
    { "data": "AddApproveTime" },
    { "data": "MobileNumber" },
    { "data": "SecondarySellerName" },
    { "data": "EmailAddress" },
    { "data": "IsActive" },
    { "data": null },
    { "data": "IsLoginPermission" },
    { "data": "IsModifyCustomerPermission" },
    { "data": "IsRaiseInvoicePermission" },
    ],
    "bLengthChange": false,
    "searching": true,
    "ordering": true,
    "deferRender": true,
    "serverSide": false,
    "autoWidth": true,
    "filter": false,
    "Length": 10,
    "paging": true,
    "columnDefs": [
        {
            "searchable": false,
            "orderable": false,
            "width": "5%",
            "targets": 0
        },
        { "width": "10%", "targets": 1 },
        { "width": "10%", "targets": 2 },
        { "width": "20%", "targets": 3 },
        { "width": "20%", "targets": 4 },
        { "width": "10%", "targets": 5 },
        {
            "render": function (data, type, row) {
                return '<a id="btnPermission" class="btn btn-tag">Permissions</a><a id="btnDeleteSecSeller" class="btn btn-tag">Deactivate</a>';
            },
            "targets": 6,
            "bSortable": false,
            "width": "20%"
        },
        { "targets": 7, "visible": false, "searchable": false },
        { "targets": 8, "visible": false, "searchable": false },
        { "targets": 9, "visible": false, "searchable": false },
    ],
    "fnRowCallback": function (nRow, aData, iDisplayIndex) {
        $("td:nth-child(1)", nRow).html(iDisplayIndex + 1);
        return nRow;
    }
});

This is working properly for single page but on moving next page it restart serial number count with 1 on each new page.
I want to resume my serial number count event on page change.

Kindly help me to solve this.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,570Questions: 26Answers: 4,996
    Answer ✓

    The iDisplayIndex is the index of the data being displayed and is reset each time the data is drawn. A couple options:

    1. Have the server create the serial number and return it in the JSON object.
    2. Use initComplete to loop through all the rows and assign the serial number after the data is loaded into the table.

    There may be other better options depending on what you are doing with the serial number.

    Kevin

This discussion has been closed.