I want to do own filtering function for SlickGrid filters, which ussually will be unify and can used in 99 % . What I missed in Slickgrid - which type of data is used in column ? Maybe it alreday exist, but after reviewing sources I didn't found . If that exist - I will be thankfulll if you direct me to true path . Slick.Editors type ? But if column isn't for editing ? ...
In samples of SlickGrid ussually use filters not allowing to data type , exist only some examples with concrete field Id. Ussually data are chars, dates, booleans and nums.
For nums types I want to improve filters with <,> and other numeric operands symbols , the same can be done and with dates types . At this time I can do that only with field ID - I can direct own global array , with fieldIds and types , and then recognize type of column from that . But this solution ins't clear - better it will be if detect column type from grid .
Many thanks in advance for any help and ideas !
ADDED :
After some search found , that I can work with SlickGrid data values types . I'm newbie with Javascript , so any help and suggestion to improve source below are welcome ... :-)
Here is mine source :
function filter( item )
{
for ( var columnId in colFilt )
{
if ( columnId !== undefined && colFilt[ columnId ] !== "" )
{
var c = grid.getColumns()[ grid.getColumnIndex( columnId ) ];
var typ = varType( item[ c.field ] );
if ( typ == "N" || typ == "D" )
{
var arr = date_num_filter( colFilt[ columnId ] )
if ( arr.length > 0 )
{
if ( arr.length == 2 )
{
switch ( arr[ 0 ] )
{
case "<" :
if ( item[ c.field ] >= arr[ 1 ] )
return false;
break;
case ">" :
if ( item[ c.field ] <= arr[ 1 ] )
return false;
break;
case "<=" :
if ( item[ c.field ] > arr[ 1 ] )
return false;
break;
case ">=" :
if ( item[ c.field ] < arr[ 1 ] )
return false;
break;
default :
return false;
}
}
else
{
if ( item[ c.field ] < arr[ 1 ] || item[ c.field ] > arr[ 3 ] )
return false;
}
}
else
{
if ( item[ c.field ] != colFilt[ columnId ] )
return false;
}
}
if ( typ == "C" ) // item[ c.field ].substring
{
if ( item[ c.field ].toLowerCase().indexOf( colFilt[ columnId ] ) == -1 ) // item[ c.field ] != colFilt[ columnId ] &&
return false;
}
}
}
return true;
}
function varType( o )
{
if ( o.toFixed )
return "N";
if ( o.substring )
return "C";
if ( o.getMonth )
return "D";
if ( o == true || o == false )
return "L";
return "U";
}
function date_num_filter( cVal )
{
var ret_arr = [];
var p = -1;
var n1,n2,n3
if ( cVal.length == 0 )
return ret_arr;
n1 = cVal.indexOf( ".." );
n2 = cVal.indexOf( "<" );
n3 = cVal.indexOf( ">" );
if ( n1 >= 0 || n2 >= 0 || n3 >= 0 )
{
p = cVal.indexOf( ".." );
if ( p >= 0 && cVal.length > 2 )
{
if ( p == 0 || p == cVal.length - 2 )
{
ret_arr[ 0 ] = ( p == 0 ? "<=" : ">=" );
ret_arr[ 1 ] = ( p == 0 ? cVal.substr( 2 ) : cVal.substr( 0, p ) );
}
else
{
ret_arr[ 0 ] = ">=";
ret_arr[ 1 ] = cVal.substr( 0, p );
ret_arr[ 2 ] = "<=";
ret_arr[ 3 ] = cVal.substr( p + 2 );
}
return ret_arr;
}
n1 = cVal.indexOf( "<=" );
n2 = cVal.indexOf( ">=" );
if ( n1 == 0 || n2 == 0 )
{
if ( cVal.length > 2 );
{
ret_arr[ 0 ] = cVal.substr( 0, 2 );
ret_arr[ 1 ] = cVal.substr( 2 );
return ret_arr;
}
}
n1 = cVal.indexOf( "<" );
n2 = cVal.indexOf( ">" );
if ( n1 == 0 || n2 == 0 )
{
if ( cVal.length > 1 );
{
ret_arr[ 0 ] = cVal.substr( 0, 1 );
ret_arr[ 1 ] = cVal.substr( 1 );
return ret_arr;
}
}
}
return ret_arr;
}
Thanks in advance !
Your english is a little hard to understand but I believe you are trying to do filtering by using some conditions like this ( > 100, != 100, <> 100 ), well I made it under my project with 2 functions. The principle is that it will start by checking the first character and if found any of these 4 symbols ( <, >, !, =) then we know it's a conditional filter, then after it will grab that condition until a space is found so you would catch any symbols with 1 or 2 chars (<, <=, <>, !=, etc...). Also the condition checks if it's a number first, because doing > 1 on a string and on a number has 2 different results.
Here are my 2 functions: