how to capture the data in a selected row using jQuery DataTables

前端 未结 2 924
醉酒成梦
醉酒成梦 2021-02-03 12:00

I have this datatable setup:

$(document).ready(function() {
    $(\'#RectifiedCount\').dataTable( {
        "bJQueryUI": true,
        "bProcessing         


        
相关标签:
2条回答
  • 2021-02-03 12:39

    I did the following:

     oTable = $('#RectifiedCount').dataTable( ....);
    
     $('#RectifiedCount tbody tr').live('click', function (event) {        
        var aData = oTable.fnGetData(this); // get datarow
        if (null != aData)  // null if we clicked on title row
        {
            //now aData[0] - 1st column(count_id), aData[1] -2nd, etc. 
        }
    });
    
    0 讨论(0)
  • 2021-02-03 12:40

    Mutch better way instead of hooking a click event, using just jquery and TableTools:

    "oTableTools": {
    "sRowSelect": "single",
    "fnRowSelected": function(node) {
        var row = $(node).find('td');
        //all cells
        $.each(row, function(index, td) {
            console.log($(td).text());
        });
    
        console.log("Specific cell content: " + $(row[2]).text());
    
    }
    

    }

    0 讨论(0)
提交回复
热议问题