legacy datatables: filter a hidden column for a value greater than x

legacy datatables: filter a hidden column for a value greater than x

rolfsfrolfsf Posts: 27Questions: 6Answers: 0
edited December 2014 in Free community support

Trying to get my head around range filtering with no max in datatables 1.9x (yes... I'm trying to get to 1.10!)

The table gets filtered when a user clicks on d3.js chart, which has an event handler. The event handler basically takes in two pieces of data from the event target -- a value (1 to 5) and a modifier ('exact' or 'at least'), and then it should filter the table on a hidden column based on those two data.

So... if it gets "2" and "exact", it's a simple use of

myTable.fnFilter(value, column);

but if it's "at least" 2, then I want to filter for any row with 2 or greater. The range filtering (numbers)
http://legacy.datatables.net/plug-ins/filtering
seems like the right approach, but I don't understand how to throw my variables at the function as it's written. It's written with a hard coded column, and it's getting min & max from a couple inputs. I don't have the inputs, and I'm hoping to make this function reusable for other tables, so the hard coded column isn't ideal either.

How can I turn:

$.fn.dataTableExt.afnFiltering.push(
    function( oSettings, aData, iDataIndex ) {
        var iColumn = 6;
        var iMin = document.getElementById('min').value * 1;
        var iMax = document.getElementById('max').value * 1;
         
        var iVersion = aData[iColumn] == "-" ? 0 : aData[iColumn]*1;
        if ( iMin == "" && iMax == "" )
        {
            return true;
        }
        else if ( iMin == "" && iVersion < iMax )
        {
            return true;
        }
        else if ( iMin < iVersion && "" == iMax )
        {
            return true;
        }
        else if ( iMin < iVersion && iVersion < iMax )
        {
            return true;
        }
        return false;
    }
);

into a reusable range filter?

Answers

This discussion has been closed.