如何在Datatables中获取行索引?

时间:2015-07-29 10:37:46

标签: javascript jquery ajax datatables

我使用以下javascript获取行索引。通过使用它,ID(表头)始终以1开始,以防每个页面中选择下一个10个值。我需要将下一个10显示为11到20.非常感谢..

  $(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 个答案:

答案 0 :(得分:1)

编辑:

请查看此链接Datatables-addrow,代码在此处:

parameter pass appointment not jsondata in severside code

        public static string save(string appointment)
        {
            var output = JsonConvert.DeserializeObject<Appointment>(appointment);
            Appointment r = (Appointment)output;
            r.Name= output.rName.ToString();
            //sql code here     
            return r.Name;
        } 

获取jquery中的索引:

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

有关详细信息,请访问Datatables