jbox-web / ajax-datatables-rails

A wrapper around DataTable's ajax methods that allow synchronization with server-side pagination in a Rails app
MIT License
590 stars 227 forks source link

how to implement datatables index column ? #259

Open buncis opened 7 years ago

buncis commented 7 years ago

I'm tring to implement index column, If we see the example https://datatables.net/examples/api/counter_columns.html we just need to throw empty and add this line

$(document).ready(function() {
    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();
} );

so I'm trying to throw null data from the server but it fails, since the counter is only count the data that send to html(only 10/based on show entries)

then I conclude the best way is to send the index column from the server itself instead calculate it in front end

@n-rodriguez any idea how to implement this?, I think its more easy to implements now, since we no longer depends on pagination gem

64 related