Retrieving row data after filtering JQuery Datatables

后端 未结 8 450
广开言路
广开言路 2020-12-28 18:09

Seems like it should be easy but...

Does anyone know how to return the current rows from a filtered dataTable? The oTable.fnGetNodes() method returns

8条回答
  •  清歌不尽
    2020-12-28 18:53

    You can get the visible rows list changing the fnGetHiddenTrNodes function as follows.

     $.fn.dataTableExt.oApi.fnGetVisibleTrNodes = function (oSettings, arg1, arg2) {
    
                /* Note the use of a DataTables 'private' function thought the 'oApi' object */
    
                var anNodes = this.oApi._fnGetTrNodes(oSettings);
                var anDisplay = $('tbody tr', oSettings.nTable);
                var visibleNodes = [];
    
                for (var i = 0; i < anDisplay.length; i++) {
                    var iIndex = jQuery.inArray(anDisplay[i], anNodes);
    
                    if (iIndex != -1) {
                        visibleNodes.push(anDisplay[i]);
                    }
                }
    
                /* Fire back the array to the caller */
                return visibleNodes;
            }
    

提交回复
热议问题