Datatable mutiple column Range filtering

Datatable mutiple column Range filtering

csurepeddicsurepeddi Posts: 3Questions: 1Answers: 0
edited March 2015 in Free community support

I'm trying to find an example where I can do range filtering on multiple columns...I'm not trying to search for a range on multiple columns.. I want multiple columns to be range range filtered at the same time...

I'm using this example for range filtering..
https://datatables.net/examples/plug-ins/range_filtering.html

I'm using textboxes on each column to get the values and doing range filter if first cahracter is '> or '<' ..otherwise I'm doing a normal search.

Problems:
1) Whenever I range filter one column it works fine, but when I range filter on another column it clears the filter on first column and filters it on the second. I want the range filter to be applied on both columns
2) whenever I enter something in textbox and clear it out, the datatable doesn't reset..

oTable = $('#requestTable').DataTable();


oTable.columns().eq( 0 ).each( function ( ) {
          $( 'thead input' ).on( 'keyup change', function () {      
                    colIdx = $("thead input").index(this);
                 filter_input = this.value;
                 first_char = filter_input.substring(0,1);
                 rem_string = filter_input.substring(1);

                if(first_char == "<" ) {
                    max = parseInt(rem_string, 10 );
                    requestWhse.oTable.draw();
                }
                else if(first_char == ">" && rem_string.length > 0){
                    min = parseInt(rem_string, 10 );
                    requestWhse.oTable.draw();
                }
                else  if(this.value == '' || this.value == null){
                    requestWhse.oTable.column( $("thead input").index(this) ).search(this.value).draw();
                }
                else if ($.isNumeric(this.value )){
                    requestWhse.oTable.column( $("thead input").index(this) ).search( "^" + this.value + "$",true).draw();
                }
                   else  if (rem_string.length == 0) {
                    requestWhse.oTable.column( $("thead input").index(this) ).search(rem_string).draw();
                }
            
         } );       
});


$.fn.dataTable.ext.search.push( 
                    function( settings, data, dataIndex ) {
                        var value = parseFloat( data[colIdx] ) || 0; 
                        if ( ( isNaN( min ) && isNaN( max ) ) ||
                                ( isNaN( min ) && value < max ) ||
                                ( min < value   && isNaN( max ) ) ||
                                ( min < value   && value < max ) )
                           {
                            return true;
                        }
                        return false;
                    }
            );

Any suggestions on how to make range filter to work simultaneously on multiple columns??

Answers

This discussion has been closed.