PDA

View Full Version : Date Filter not working



matscher
23 Mar 2012, 8:04 AM
Hi,
I trie to filter a date-column with datefilter from the filtersfeature. I used the PHP-code from the GridFilter-example. Unfortunately, the server doesn't receive the filter param.


var encode = false;
filters = {
ftype: 'filters',
encode: encode,

};



{
xtype: 'gridcolumn',
dataIndex: 'date_at',
width: 90,
align: 'center',
text: 'date_at',
filter: {

type: 'date'


},
renderer: Ext.util.Format.dateRenderer('m/d/Y')

},




xtype: 'gridpanel',
itemId: 'wsImportGridPanel',
store: 'wsImportStore',
features: [filters],


PHP-Code

$filters = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : null;

if (is_array($filters)) {
$encoded = false;
} else {
$encoded = true;
$filters = json_decode($filters);
}

$where = ' 0 = 0 ';
$qs = '';

// loop through filters sent by client
if (is_array($filters)) {
for ($i=0;$i<count($filters);$i++){
$filter = $filters[$i];

// assign filter data (location depends if encoded or not)
if ($encoded) {
$field = $filter->field;
$value = $filter->value;
$compare = isset($filter->comparison) ? $filter->comparison : null;
$filterType = $filter->type;
} else {
$field = $filter['field'];
$value = $filter['data']['value'];
$compare = isset($filter['data']['comparison']) ? $filter['data']['comparison'] : null;
$filterType = $filter['data']['type'];
}

switch($filterType){
case 'string' : $qs .= " AND ".$field." LIKE '%".$value."%'"; Break;
case 'list' :
if (strstr($value,',')){
$fi = explode(',',$value);
for ($q=0;$q<count($fi);$q++){
$fi[$q] = "'".$fi[$q]."'";
}
$value = implode(',',$fi);
$qs .= " AND ".$field." IN (".$value.")";
}else{
$qs .= " AND ".$field." = '".$value."'";
}
Break;
case 'boolean' : $qs .= " AND ".$field." = ".($value); Break;
case 'numeric' :
switch ($compare) {
case 'eq' : $qs .= " AND ".$field." = ".$value; Break;
case 'lt' : $qs .= " AND ".$field." < ".$value; Break;
case 'gt' : $qs .= " AND ".$field." > ".$value; Break;
}
Break;
case 'date' :
switch ($compare) {
case 'eq' : $qs .= " AND ".$field." = '".date('m/d/Y',strtotime($value))."'"; Break;
case 'lt' : $qs .= " AND ".$field." < '".date('m/d/Y',strtotime($value))."'"; Break;
case 'gt' : $qs .= " AND ".$field." > '".date('m/d/Y',strtotime($value))."'"; Break;
}
Break;
}
}
$where .= $qs;
}

$_result = $_db->query("SELECT * FROM ws_import WHERE ".$where." LIMIT 500")



{"action":"QueryDatabase","method":"getResults","data":[{"filter[0][field]":"date_at","filter[0][data][type]":"date","filter[0][data][comparison]":"eq","filter[0][data][value]":"02/01/2012","page":1,"start":0,"limit":100,"sort":"date_at","dir":"ASC"}],"type":"rpc","tid":2}


Can someone help me, please?

matscher
24 Mar 2012, 12:11 AM
No ideas?