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

2

2

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>
Lanza answered 24/3, 2018 at 16:30 Comment(0)
L
2

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')
Lanza answered 24/3, 2018 at 17:23 Comment(1)
This is how it worked for me on datatables v1.10. I suggest you post this as a full answer to the other question #31458560Courtland
I
0

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

Iveson answered 14/3, 2019 at 21:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.