Individual column search with filtering greater values?

Individual column search with filtering greater values?

krychaj5krychaj5 Posts: 19Questions: 8Answers: 0

Hello!
I'm looking for solution to implement "range filter" into column search, I'm using this datatable:
https://datatables.net/examples/api/multi_filter.html

I have found this example: https://datatables.net/examples/plug-ins/range_filtering.html

And I just need to add "minimum" search into all columns in my individual column search table.
For example: now when I'm searching for "5" it's showing me only columns with "5", I want to see 5+ values also.

Thanks for replies, Krystian.

Answers

  • kthorngrenkthorngren Posts: 21,682Questions: 26Answers: 5,019
    edited May 2017

    I combined both examples and came up with this:
    http://live.datatables.net/hagipapu/1/edit

    Use the Age column to test the code.

    I added an id, using the column title, to each column search box:

            $(this).html( '<input type="text" id="' + title + '" placeholder="Search '+title+'" />' );
    

    The event executes when typing into the Age column search:

            $( '#Age' ).on( 'keyup change', function () {
                        table.draw();
                }
            );
    

    Modified the search API function to return true if the column is NaN or the column value is >= to the search input:

    $.fn.dataTable.ext.search.push(
        function( settings, data, dataIndex ) {
            var min = parseInt( $('#Age').val(), 10 );
            var age = parseFloat( data[3] ) || 0; // use data for the age column
            if ( ( isNaN( min ) ) ||
                 ( age >= min))
            {
                return true;
            }
            return false;
        }
    );
    
    

    Hopefully you can adapt this to your solution. Someone may post a better alternative solution.

    Kevin

  • krychaj5krychaj5 Posts: 19Questions: 8Answers: 0

    Sorry kthorngren but I still can't connect this solution with my exact table, can You have look at it?
    http://live.datatables.net/bododudu/1/

    I want to make column "BTS" searchable but it isnt working.

  • kthorngrenkthorngren Posts: 21,682Questions: 26Answers: 5,019

    Columns start counting from 0. Changed the column reference and it appears to work:

    var age = parseFloat( data[5] )
    

    Kevin

This discussion has been closed.