Hi ,
I wanna to improve this code :
function custom_filter($filter_by)
{
$index = $filter_by->index("some_field");
if ($index!==false) //there is client side input for the filter
$filter_by->rules[$index]["operation"]=">";
}
$conn->attach->event("beforeFilter","custom_filter");
Mine efforts are to do this code with some own rules, of course . I’m seeing that mine rules will be managed by field type of query - varchar , float , int, date and etc. . The main barrier for me is to define this fields types , not directing field names manually as in sample above ( “some_field” ). Can dhtmlx guru to help how to do that ? . Now I’m sending to php fields or sql query, but don’t know how to retrieve field types from that .
Code :
require_once( "config.php" );
require( "php/codebase/grid_connector.php" );
require( "php/codebase/db_mysqli.php" );
$slc_fld = $_GET[ 'fld' ];
$slc_db = $_GET[ 'd_b' ];
$slc_arr = explode( ",", $slc_fld );
function grid_serv_filter( $filter_by )
{
global $slc_arr;
$i = 0;
foreach ( $slc_arr as &$value )
{
$index = $filter_by->index( $value );
if ( $index !== false )
{
$cVal = $filter_by->rules[ $index ][ "value" ];
$type = mysql_field_type( );
// here is the problem - mysql_field_type() retrieve field type from real query ...
if ( $type == "char" and etc )
{
if ( strlen( $cVal ) > 0 )
{
$cVal = $filter_by->rules[ $index ][ "value" ];
if ( substr( $cVal, 0, 1 ) == "%" )
$cVal = substr( $cVal, 1 );
$filter_by->rules[ $index ][ "operation" ] = " LIKE ";
$filter_by->rules[ $index ][ "value" ] = $cVal."%";
}
}
if ( $type == numeric and etc )
{
include 'num_oper.php';
$arr = num_filter( $cVal );
if ( count( $arr ) > 0 )
{
if ( $arr[ 0 ] !== 'nera' )
$filter_by->rules[ $index ][ "value" ] = $arr[ 0 ];
$filter_by->rules[ $index ][ "operation" ] = $arr[ 1 ];
if ( count( $arr ) == 3 )
$filter_by->add( $value, $arr[ 2 ], "<=" );
}
}
... and etc ...
}
$i ++;
}
}
$link = new mysqli( $myServ, $myUser, $myPasw, $myDb );
if ( $link->connect_errno )
die( 'Prisijungimo klaida : (' . $link->connect_errno . ') ' . $link->connect_error );
$grid = new GridConnector( $link, "MySQLi" );
$grid->dynamic_loading( 100 );
//$grid->enable_log( "temp.log", true );
$slct = new OptionsConnector( $link, "MySQLi" );
$slct->render_sql( "select preke as value, preke as label from prekes where prek_tipas = 'Gaminys' and db = '".$slc_db."' order by preke asc", "", "preke(value),preke(label)" );
$grid->set_options( "preke", $slct );
$grid->event->attach( "beforeFilter", "grid_serv_filter" );
$grid->render_sql( "select ".$slc_fld." from uzsakym where uzsakym.db = '".$slc_db."'", "uzsak", $slc_fld );
At this time is a sample with one table . But in future will be some complex queries with some tables . So I’m emphasizing “query” . Maybe exist a better solution for that , but didn’t found . As for novice with js and php , it’s diccifult to understand so many code of dhtmlx , so any help will be valuable …
With best regards !