PDA

View Full Version : Filter a datecolumn not working



matscher
28 Mar 2012, 7:10 AM
Hi,
I try to filter several columns in a grid with remoteFilter. I don't use any filter features. For normal gridcolumns my filter works fine but if I try to filter a datecolumn, no rows get displayed. So as if no rows with these values are in the database. But there are many.

Here the response from a gridolumn:


{"type":"rpc","tid":1,"action":"QueryDatabase","method":"getResults","result":{"success":true,"total":10128,"records":[{"cp_id":null,"cp_custu....


And here the response from the datecolumn:


{"type":"rpc","tid":1,"action":"QueryDatabase","method":"getResults","result":{"success":true,"total":10128,"records":[]}}




In both cases I use the same code to filter the columns and the filter-params are send correct to the server.
For example:


Object { property="date_at", value="2012-02-09"}



My store looks like this:

Ext.create('MyApp.store.Store', {
extend: 'Ext.data.Store',

remoteSort: true,
remoteFilter: true,
buffered: true
});



The filter-values come from a form in an other window. The filter-function in my controller looks like this:

doPreFilter: function() {

var store = this.getMyGridPanel().store;
var win = this.getFilterWindow();
var values = win.down('form').getValues();
var filters = [];

for (var p in values) {
var value = values[p];
if (value) {
filters.push({ property: p, value: value });
}
}

store.filter(filters);



The datecolumn in the grid looks like this:

{
xtype: 'datecolumn',
dataIndex: 'date_at',
format: 'Y-m-d',
width: 90,
align: 'center',
text: 'date_at',
},



The datepicker for the filter-values lokks like this:

items: [
{
xtype: 'datefield',
name: 'date_at',
format: 'Y-m-d',
submitFormat: 'Y-m-d',
fieldLabel: 'Date From',
anchor: '100%'
},



I'm really clueless and hope there's someone who can help me solve problem.

Many thanks

mitchellsimoens
28 Mar 2012, 8:46 AM
You say you are using remoteFilter so that means the filtering is happening on the server correct? Did you look at the request to see the filter param?

matscher
28 Mar 2012, 10:59 AM
Yes, I looked at the request parameter and everything seems to be ok.

Here:

{"action":"QueryDatabase","method":"getResults","data":[{"page":1,"start":0,"limit":25,"filter":[{"property":"date_at","value":"2012-02-09"}]}],"type":"rpc","tid":1}

mitchellsimoens
28 Mar 2012, 11:04 AM
If it returns an empty array then something server-side is going wrong

matscher
28 Mar 2012, 11:12 AM
Thank you for your reply.

It's strange that the same code works perfect for a gridcolumn.

Here's my PHP-code, but it should be ok, because I used it several times without any problems.


<?php

class QueryDatabase
{
public function getResults(stdClass $params)
{
$_db = $this->__construct();

$start = $params->start;
$limit = $params->limit;

$filter_1 = $params->filter[0]->property;
$filter_2 = $params->filter[0]->value;

$allRows = $_db->query("SELECT * FROM ws_import");

$_result = $_db->query("SELECT * FROM ws_import WHERE ".$filter_1. " = ".$filter_2. " LIMIT 300") or die('Connect Error (' . $_db->connect_errno . ') ' . $_db->connect_error);

$results = array();

$results['success'] = true;

$results['total'] = $allRows->num_rows;

$temp_array = array();

while ($row = $_result->fetch_assoc()) {
array_push($temp_array, $row);
}

$results['records'] = $temp_array;

return $results;

$results->close();
}
}
?>


I'm completely stumped.

matscher
28 Mar 2012, 11:21 AM
I got it!
Date-values have to be send in ' ' .

This works:

var win = this.getFilterWindow();
var values = win.down('form').getValues();
var filters = [];

for (var p in values) {
var value = values[p];
if (value) {
filters.push({ property: p, value: "'"+value+"'" });
}
}

store.filter(filters);


This works but i don't know if it's the best solution.