Get 'data-sort' orthogonal value from DataTables within search.push function

和自甴很熟 提交于 2019-12-10 23:36:23

问题


I am looping the rows within $.fn.dataTable.ext.search.push function to select some rows based on many criteria. I am setting some values on the TD of the tables known as orthogonal data. I am trying to get the value of the 'data-sort' but I don't know how. I am able to get the cell's inner data via data[2] (for column 2), but not the 'data-sort' or 'data-filter'. Any ideas?

$.fn.dataTable.ext.search.push(
    function (settings, data, dataIndex) {

        var iRating = parseFloat(data[2]) || 0; // this works 
        var datasort = //somehow get the data-sort from the TD
);

HTML

<td data-sort="57000" class=" seqNum">.....</td>

回答1:


Looks like this way I can get the value. If there are any other better ways please advice:

$(settings.aoData[dataIndex].anCells[2]).data('sort')



回答2:


Yes there is an easier way.

The data parameter is the "search data" for the row. i.e. the values for "filter" data for each col - not your "sort" data / anything else.

But you also have access to the full data object for the row i.e. the 4th parameter - rowData.

So you need to use rowData at the index of the column you want (you say 'for column 2', zero based so - 2 would be for the 3rd column).

Then you should find a property called 'sort' :

function(settings, searchData, index, rowData, counter){
    var dataSort = rowData[1]['sort'];
    console.log(`This should be the value you want : ${dataSort}`); 
}

As per the documentation here



来源:https://stackoverflow.com/questions/49467125/get-data-sort-orthogonal-value-from-datatables-within-search-push-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!