Surinder singh
17 Mar 2011, 11:11 PM
Hi,
We are sharing our extjs,joomla mootool,jquery extensions on http://www.developerextensions.com
one of them is Grid FilterRow by which you can filter the grid from server side.
You can add any kind of input filter like DropDown/Combobox, Textfield, NumberField, DateField Etc
And You can clear all filters by one click.
In this extension you can add more filter options like
1) if you have a date filter
then options can be [After,Before,Is,ETC]
2)if you have a text filter
then options can be [Equal,Contains,Start With,End With]
3)if there is number filter
then options can be [Equal,Greater than,Less Than,Start With,End With, ETC....]
it is opto you, how u can add more options in backend and frontend, let me show you, how it works
FrontEnd settings:
Grid Columns Configurations:-
var sampleGridColumns= [{
header: 'Id',
width:90,
dataIndex: 'id',
clearFilter:true//used to show clear filter icon in this column
},{
header: 'Title',
dataIndex: 'title',
sortable: true,
width:150,
filterInput: new Ext.form.TextField(),
filterOptions:[{value:'startwith', text:'Start With'},{value:'endwith', text:'End With'},{value:'contain', text:'Contain'},{value:'doesnotcontain', text:'Does Not Contain'}]
},{
header: 'Alias',
dataIndex: 'alias',
sortable: true,
width:230,
filterInput: new Ext.form.TextField(),
filterOptions:[{value:'startwith', text:'Start With'},{value:'endwith', text:'End With'},{value:'contain', text:'Contain'},{value:'doesnotcontain', text:'Does Not Contain'}]
},{
header: 'Created',
width:130,
dataIndex: 'created_date',
filterInput: new Ext.form.DateField({format:'Y-m-d', dataIndex:'created' /* you can pass different dataIndex for filtering into all filter inputs */}),
filterOptions:[{value:'before', text:'Before'},{value:'after', text:'After'},{value:'contain', text:'Is'}]
},{
header: 'Published',
dataIndex: 'state',
sortable: true,
renderer:function(v){if(v==1){return 'Published'}else{return '<span style="color:red">UnPublished</span>'}},
filterInput : new Ext.form.ComboBox({
displayField : 'name',
valueField : 'state',
triggerAction : 'all',
typeAhead : false,
mode : 'local',
listWidth : 160,
hideTrigger : false,
emptyText : 'Select',
store :[['1','Published'],['0','UnPublished']]
}),
filterOptions:[{value:'equal', text:'Is'},{value:'notequal', text:'Not'}]
}];
Backend handler:
<?php
error_reporting(E_ALL&~E_NOTICE);
include('db.php');
/**
* Gets Atricals from the com_extensiondemo_content table by filtering them accroding to $filter option
*
* @param $filter as array ('name'=>"John", "name_filterOption"=>'startwith', 'email'=>'@yahoo.com', "email_filterOption"=>'endwith')
*
* @access public
* @return records found
*/
function filteredMembers( $filter ="" ){
$where = " WHERE ";
$where .= buildFilterCondition($filter);
$sql = "SELECT *, DATE_FORMAT(created, '%b %e, %Y') as created_date FROM com_extensiondemo_content ".$where;
if( $offset > 0 ){
$sql .= " LIMIT ".intval($start).",".intval($offset);
}
$return = loadObjectlist($sql);
return $return;
}
/**
* build the filter condition for query
*
* @param $filter as array ('name'=>"John", "name_filterOption"=>'startwith', 'email'=>'@yahoo.com', "email_filterOption"=>'endwith')
*
* @access public
* @return filter as string
*/
function buildFilterCondition($filter){
$where = ' 1=1 ';
if( $filter && is_array($filter) && count($filter) ){
foreach($filter as $fieldIndex=>$val){
if( substr($fieldIndex, -12 ) == 'filterOption' ){
$fieldName = str_replace('_filterOption', '', $fieldIndex);
$fieldValue = $filter[$fieldName];
if($fieldValue===''){
continue;
}
switch($val){
case 'startwith':
$where .= " AND {$fieldName} like '{$fieldValue}%' ";
break;
case 'endwith':
$where .= " AND {$fieldName} like '%{$fieldValue}' ";
break;
case 'doesnotcontain':
$where .= " AND {$fieldName} NOT like '%{$fieldValue}%' ";
break;
case 'equal':
$where .= " AND {$fieldName} = '{$fieldValue}' ";
break;
case 'notequal':
$where .= " AND {$fieldName} <> '{$fieldValue}' ";
break;
case 'before':
$where .= " AND {$fieldName} < '{$fieldValue}' ";
break;
case 'after':
$where .= " AND {$fieldName} > '{$fieldValue}' ";
break;
case 'NoFilter':
break;
default:
case 'contain':
$where .= " AND {$fieldName} like '%{$fieldValue}%' ";
break;
}
}
}
}
return $where;
}
$filter = $_REQUEST['filter'];
$rows = filteredMembers($filter);
$result = new stdClass();
$result->data = $rows;
$result->total = count($rows);
$result->success = true;
echo $json = json_encode($result);
?>
Demo URL: http://www.developerextensions.com/index.php?option=com_extensiondemo&view=extensiondemo&layout=ext&extension=Ext-FilterRow_1.2&Itemid=482
(http://www.developerextensions.net)
We are sharing our extjs,joomla mootool,jquery extensions on http://www.developerextensions.com
one of them is Grid FilterRow by which you can filter the grid from server side.
You can add any kind of input filter like DropDown/Combobox, Textfield, NumberField, DateField Etc
And You can clear all filters by one click.
In this extension you can add more filter options like
1) if you have a date filter
then options can be [After,Before,Is,ETC]
2)if you have a text filter
then options can be [Equal,Contains,Start With,End With]
3)if there is number filter
then options can be [Equal,Greater than,Less Than,Start With,End With, ETC....]
it is opto you, how u can add more options in backend and frontend, let me show you, how it works
FrontEnd settings:
Grid Columns Configurations:-
var sampleGridColumns= [{
header: 'Id',
width:90,
dataIndex: 'id',
clearFilter:true//used to show clear filter icon in this column
},{
header: 'Title',
dataIndex: 'title',
sortable: true,
width:150,
filterInput: new Ext.form.TextField(),
filterOptions:[{value:'startwith', text:'Start With'},{value:'endwith', text:'End With'},{value:'contain', text:'Contain'},{value:'doesnotcontain', text:'Does Not Contain'}]
},{
header: 'Alias',
dataIndex: 'alias',
sortable: true,
width:230,
filterInput: new Ext.form.TextField(),
filterOptions:[{value:'startwith', text:'Start With'},{value:'endwith', text:'End With'},{value:'contain', text:'Contain'},{value:'doesnotcontain', text:'Does Not Contain'}]
},{
header: 'Created',
width:130,
dataIndex: 'created_date',
filterInput: new Ext.form.DateField({format:'Y-m-d', dataIndex:'created' /* you can pass different dataIndex for filtering into all filter inputs */}),
filterOptions:[{value:'before', text:'Before'},{value:'after', text:'After'},{value:'contain', text:'Is'}]
},{
header: 'Published',
dataIndex: 'state',
sortable: true,
renderer:function(v){if(v==1){return 'Published'}else{return '<span style="color:red">UnPublished</span>'}},
filterInput : new Ext.form.ComboBox({
displayField : 'name',
valueField : 'state',
triggerAction : 'all',
typeAhead : false,
mode : 'local',
listWidth : 160,
hideTrigger : false,
emptyText : 'Select',
store :[['1','Published'],['0','UnPublished']]
}),
filterOptions:[{value:'equal', text:'Is'},{value:'notequal', text:'Not'}]
}];
Backend handler:
<?php
error_reporting(E_ALL&~E_NOTICE);
include('db.php');
/**
* Gets Atricals from the com_extensiondemo_content table by filtering them accroding to $filter option
*
* @param $filter as array ('name'=>"John", "name_filterOption"=>'startwith', 'email'=>'@yahoo.com', "email_filterOption"=>'endwith')
*
* @access public
* @return records found
*/
function filteredMembers( $filter ="" ){
$where = " WHERE ";
$where .= buildFilterCondition($filter);
$sql = "SELECT *, DATE_FORMAT(created, '%b %e, %Y') as created_date FROM com_extensiondemo_content ".$where;
if( $offset > 0 ){
$sql .= " LIMIT ".intval($start).",".intval($offset);
}
$return = loadObjectlist($sql);
return $return;
}
/**
* build the filter condition for query
*
* @param $filter as array ('name'=>"John", "name_filterOption"=>'startwith', 'email'=>'@yahoo.com', "email_filterOption"=>'endwith')
*
* @access public
* @return filter as string
*/
function buildFilterCondition($filter){
$where = ' 1=1 ';
if( $filter && is_array($filter) && count($filter) ){
foreach($filter as $fieldIndex=>$val){
if( substr($fieldIndex, -12 ) == 'filterOption' ){
$fieldName = str_replace('_filterOption', '', $fieldIndex);
$fieldValue = $filter[$fieldName];
if($fieldValue===''){
continue;
}
switch($val){
case 'startwith':
$where .= " AND {$fieldName} like '{$fieldValue}%' ";
break;
case 'endwith':
$where .= " AND {$fieldName} like '%{$fieldValue}' ";
break;
case 'doesnotcontain':
$where .= " AND {$fieldName} NOT like '%{$fieldValue}%' ";
break;
case 'equal':
$where .= " AND {$fieldName} = '{$fieldValue}' ";
break;
case 'notequal':
$where .= " AND {$fieldName} <> '{$fieldValue}' ";
break;
case 'before':
$where .= " AND {$fieldName} < '{$fieldValue}' ";
break;
case 'after':
$where .= " AND {$fieldName} > '{$fieldValue}' ";
break;
case 'NoFilter':
break;
default:
case 'contain':
$where .= " AND {$fieldName} like '%{$fieldValue}%' ";
break;
}
}
}
}
return $where;
}
$filter = $_REQUEST['filter'];
$rows = filteredMembers($filter);
$result = new stdClass();
$result->data = $rows;
$result->total = count($rows);
$result->success = true;
echo $json = json_encode($result);
?>
Demo URL: http://www.developerextensions.com/index.php?option=com_extensiondemo&view=extensiondemo&layout=ext&extension=Ext-FilterRow_1.2&Itemid=482
(http://www.developerextensions.net)