filter number column from grid

filter number column from grid

ssurajita111ssurajita111 Posts: 14Questions: 6Answers: 0

Hi ,

I wanted to filter values from columns which are of number type from the grid. The filters should include operations like greater than,less than,equal to,not equal to etc.
I found the below code. I did not understand the piece of code. And it is not retrieving anything. can somebody tell me where I am going wrong?What is the use of Table1.fnDraw();

Table1 - table id
id - textfield id where I have to give the value for search //present in header of grid
colNo - Index of column

Sample code for greaterThan.

greaterThan: function(Table1, id, colNo){

        $.fn.dataTableExt.afnFiltering.push(
                function( oSettings, aData, iDataIndex ) {
                    val = ($(id).val()).trim();
                    var iMin = val * 1;
                    var iMax = 9.9 * 1;
                    var iVersion = aData[colNo] == "-" ? 0 : aData[colNo]*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;
                }
            );
            Table1.fnDraw();
    },

Thanks,
Soumya

Answers

  • ssurajita111ssurajita111 Posts: 14Questions: 6Answers: 0

    Hi,

    Somehow I fixed this as I was not able to understand the function that I posted .. hence I created my own custom function.

    PFB the workaround function.
    greaterThanCustom : function(Table1, id, colNo){
    console.log("greaterThanCustom",Table1);

               colNo = colNo-1;
                $.fn.dataTableExt.afnFiltering.push(
                        function( oSettings, aData, iDataIndex ) {
                               val = ($(id).val()).trim();
                                var max = val * 1;
                                if (aData[colNo] > max)
                                {
                                    return true;
                                }
                                return false;
    
                        }
                    );
                    Table1.fnDraw();
            },
    

    But after firing this event when I try for other events(like less than/equals etc) it is actually not filtering from the whole table , instead it is again searching from the rows that is already filtered by using the above function.

    What I need is if any other event is happening it should filter from whole table. But Again I don't need a force refresh here which is going to be visible in UI(like load mask)

    Thanks,
    Soumya

This discussion has been closed.