3

I used following javascript to get row index. By using this the ID(table header) always starts with 1 in case next 10 values are selected in every page.i need to show next 10 as 11 to 20. Thank you very much..

  $(document).ready(function() {
             $('#example').dataTable( {
                "processing": true,
        "serverSide": true,
                "ajax": "scripts/server_processing.php",

                "aoColumns": [
                    {
                        "sTitle": "ID"},

                    {
                        "sTitle": "E Mail"},
                    {
                        "sTitle": "FirstName"},
                    {
                        "sTitle": "LastName"},
                    {
                        "sTitle": "Company"},
                    {
                        "sTitle": "Course"},
                    {
                        "sTitle": "Module"},
                    {
                        "sTitle": "Completions"},
                    {
                        "sTitle": "First"},
                    {
                        "sTitle": "Last",
                        "sClass": "center"},
                    {
                        "sTitle": "Lowest"},
                    {
                        "sTitle": "Highest",
                        "sClass": "center"},

//                    {
//                        "sTitle": "#"},
                ],

                 "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                     var index = iDisplayIndex +1;
                     $('td:eq(1)',nRow).html(index);
                     return nRow;
                 }


            });


        });
1

1 Answer 1

3

EDIT:

Check out this link Datatables-addrow and code is here:

var t = $('#example').DataTable( {
        "columnDefs": [ {
            "searchable": false,
            "orderable": false,
            "targets": 0
        } ],
        "order": [[ 1, 'asc' ]]
    } );

    t.on( 'order.dt search.dt', function () {
        t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
            cell.innerHTML = i+1;
        } );
    } ).draw();

For getting index in jquery :

$('#example tbody').on( 'click', 'tr', function () {
    alert( 'Row index: '+table.row( this ).index() );
} );

For more information visit Datatables

Sign up to request clarification or add additional context in comments.

4 Comments

Thanx but I want to show row index column in table.
Match your html code, javascript code properly. any errors in console ?
<table id="example" class="display select" cellspacing="0" width="100%">
@Dim236 It works for all in the demo. You must recheck it once more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.