jQuery: Accessing table rows of second and further pages of a datatable

前端 未结 2 665
长发绾君心
长发绾君心 2021-01-14 16:30

I am retrieving table row data like this from a HTML table.

var descriptions = [];

var testRows = $(\'#tbl\').find(\'tbody\').find(\'tr\');
$this = $(this);         


        
2条回答
  •  囚心锁ツ
    2021-01-14 17:09

    I retrieved the data using fnGetNodes API method.

    Correct version (Aug 1 2013)

    var descriptions = [];
    
    var _testDesc;
    var dt = $("tbl").dataTable();
    
    var dtNodes = dt.fnGetNodes;
    var dtNodeCount = dtNodes.length;
    
    for (var i = 0; i < dtNodeCount; i++) {
        var description = $(dtNodes[i].cells[2].innerHTML).val();
        descriptions.push(description);
    }
    

    Wrong version ( Jul 31 2013)

    var descriptions = [];
    
    var _testDesc;
    var dt = $("tbl").dataTable();
    
    var dtElementCollection = dt.DataTable.settings[0].aoData;
    var dtECLength = dtElementCollection.length;
    
    for (var i = 0; i < dtECLength; i++) {
        var description = dtElementCollection[i]._aData[2];
        _testDesc = $(description).val();
        descriptions.push(_testDesc);
    }
    

提交回复
热议问题