jquery datatable服务器端按数据库ID处理选择行

时间:2014-05-19 14:34:54

标签: javascript php jquery

我使用自制的php框架和jquery datatable与服务器端处理方法。我在标题中用php自动编写脚本,一切正常。现在我尝试找到一种方法,通过datatable-result中的数据库索引字段突出显示特定行,在本例中为“manid"”。什么是最好的方法? 她的我的javascript:

    var oTable;
var giRedraw = false;

$(document).ready(function(){
    oTable = $('#dt_sys_man').dataTable({
        /* Column Width */
        "aoColumns": [
            { "bVisible": true,"sWidth": "2%","sClass":"ClickClass" },
            { "sWidth": "98%","sClass":"ClickClass" }
            ],

        /* Serverside Prozessing(Ajax) */
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "index.php?res=dt_sys_man",


        /* Default Settings */               
    "bAutoWidth": false,
    "iDisplayLength": 25,
    "aaSorting": [[ 0, "asc" ]],
    "bSortable": false,
        "bPaginate": false,
        "bFilter": false,
        "bInfo": false,
    });

    /* Row Click */
    $('#dt_sys_man tbody td.ClickClass').live('click',function(){
        var aPos = oTable.fnGetPosition(this);
        var aData = oTable.fnGetData(aPos[0]);
        /*
        $("#dt_sys_man tbody tr").removeClass('row_selected');        
        $(this).addClass('row_selected');
        */
        window.location = "index.php?do=sys-man&manid="+aData[0]+"&uid=0";
        });

    /* highlite row */
    $("#dt_sys_man tbody tr").live("click", function(event){
          $("td.row_selected", oTable.fnGetNodes()).removeClass('row_selected');
          $(event.target).parent().find("td").addClass('row_selected');
        });
});   

HTML:

<table cellpadding="0" cellspacing="0" border="0" class="display" id="dt_sys_man" width="100%">
<thead>
    <tr>
        <th>MANID</th>
        <th>Mandant</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td colspan="5" class="dataTables_empty">Loading data from server</td>
    </tr>
</tbody>
<tfoot>
    <tr>
        <th></th>
        <th></th>
    </tr>
</tfoot>

1 个答案:

答案 0 :(得分:0)

您可以使用fnRowCallback

"aoColumns": [
            { "bVisible": true,"sWidth": "2%","sClass":"ClickClass" },
            { "sWidth": "98%","sClass":"ClickClass" }
            ],
            "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
               if(aData.manid == 'whatever you're checking for'){
                     $(nRow).css('text-decoration', 'line-through');
               }
               return nRow;
}

此示例检查manid值,如果匹配,则将直通类应用于

更新:既然你已经详细阐述了你的问题,我就会发现这并不是你想要的......但是,如果你用aData传回最后点击的rowid然后你可以使用这种方法。