EasyUI Forum
May 20, 2024, 01:51:02 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to do datagrid remote filter  (Read 11819 times)
kasthuri
Newbie
*
Posts: 3


View Profile Email
« on: August 14, 2014, 06:53:21 PM »

I wanted to do datagrid with remote filter but I couldn't find any tutorial in the website. Can anyone help me?
Thanks in advance.
Logged
A-K
Full Member
***
Posts: 122


View Profile WWW
« Reply #1 on: August 15, 2014, 12:35:07 AM »

You can download the latest extension of datagrid filter from here: http://www.jeasyui.com/extension/datagrid_filter.php
and after you add it to your project just set {remoteFilter : true}

Code:
$('#dg).datagrid({
 remoteFilter : true
});
Logged
acreonte82
Jr. Member
**
Posts: 85



View Profile
« Reply #2 on: August 15, 2014, 04:16:55 AM »

I wanted to do datagrid with remote filter but I couldn't find any tutorial in the website. Can anyone help me?
Thanks in advance.

This is my solution:
1. enable the remote filter. After this u have to setup ur server side code to accept this new mode.
Code:
$('#laboratory_results').datagrid({
url: getParameters(),
        remoteFilter:true
});
nb: my getParameters() is a function that build the url with the header request

2. now u have to setup the filter in specific columns:
  a- field: the custom rule on.
  b- type: the filter type, possible values are: label,text,textarea,checkbox,numberbox,validatebox,datebox,combobox,combotree.
  c- options: the options of the filter type.
  d-  op: the filter operation, possible values are: contains,equal,notequal,beginwith,endwith,less,lessorequal,greater,greaterorequal.
The js code (this is my example)
Code:
$('#laboratory_results').datagrid('enableFilter',[{
field:'type_of_result',
                type:'combobox',
                options:{
                    panelHeight:'auto',                  
                    url:returnFilterValue(),
                    onChange:function(value){
                        if (value == ''){                        
                            $('#laboratory_results').datagrid('removeFilterRule');
                            var cc = $('#risultati_laboratorio').datagrid('getFilterComponent', 'type_of_result');
   cc.combobox('reload');                      
                            
                        } else {
                            $('#laboratory_results').datagrid('addFilterRule', {
                                field: 'type_of_result',
                                op: 'equal',
                                value: value
                            });                          
                        }
                         $('#laboratory_results').datagrid('doFilter');
                    }
                }
            },
            {
                field:'sample_number',
                type:'text',
                options:{precision:1},
                op:['equal','beginwith']
            },
            {
                field:'genotype_old',
                type:'text',
                options:{precision:1},
                op:['equal','beginwith']
            },
            {
                field:'genotype',
                type:'text',
                options:{precision:1},
                op:['equal','beginwith']
            }

        ]);
nb: returnFilterValue() is a js function that build an URL with some headers request, then the php return a groupped filter value

3- now u have to build a php script that take the filter value and then build a dynamic query to get the result
Code:
   $filterRules=array();
   if (isset($_REQUEST['filterRules'])){
$filterRules=json_decode($_REQUEST['filterRules'],true);
   }
nb: the datagrid, after you call the method 'doFilter' send a request named 'filterRules' witch contain a json array
Now u have to build a function that build ur filter query
Code:
function filterQuery($filterArray,$table){

$num_filter=count($filterArray);
#I start with 'AND because I've to attach the result at the master query
$where=" AND ";
$tmpdatafield = "";
for ($i=0; $i < $num_filter; $i++)  {

$filterdatafield =$table."_analisys_to_perform.".$filterArray[$i]['field']; #field
$filtervalue=$filterArray[$i]['value'];#value researched

# determined when I change filter field value
if ($tmpdatafield == ""){
$tmpdatafield = $filterdatafield;
} else if ($tmpdatafield <> $filterdatafield){
$where .= " AND ";
}

#I build the filter query upon the filter value selected
switch($filterArray[$i]['op']){
case 'contains';
$where .= $filterdatafield . " LIKE '%" . $filtervalue ."%'";
break;
case 'equal';
$where .=  $filterdatafield . " = '" . $filtervalue ."'";
break;
case 'notequal';
$where .= $filterdatafield . " <> '" . $filtervalue ."'";
break;
case 'beginwith';
$where .= $filterdatafield . " LIKE '" . $filtervalue ."%'";
break;
case 'endwith';
$where .= $filterdatafield . " LIKE '%" . $filtervalue ."'";
break;
case 'less';
$where .= $filterdatafield . " < " . $filtervalue ."'";
break;
case 'lessorequal';
$where .= $filterdatafield . " <= " . $filtervalue ."'";
break;
case 'greater';
$where .= $filterdatafield . " > " . $filtervalue ."'";
break;
case 'greaterorequal';
$where .= $filterdatafield . " >= " . $filtervalue ."'";
break;

}
$tmpdatafield = $filterdatafield;

}
return $where;
}

Hope this can be usefull for u and for other peoples...
If stworthy want, can post my php function filterQuery in the documentation (please refer to my name)
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!