EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Stefan B. on July 01, 2014, 04:22:51 AM



Title: DataGrid Filter Row - Use remote datebox filter with the Date as long value?
Post by: Stefan B. on July 01, 2014, 04:22:51 AM
We will use the DataGrid Filter Row with an datebox filter.
Code:
field:'changeDate',
type:'datebox',
op:['equal','notequal','less','lessorequal','greater','greaterorequal'],
options:{
  panelWidth: '240',
  editable: true
}

But the filter extension only send the date as value string to the remote server (FilterRules) like this
Code:
<jsonFilterRules: [{"field":"changeDate","op":"equal","value":"01.06.2014"}]>

But the DAO on server side use a Date field as a long value (not a String value).

How can we use the datebox filter to send the "long date value" from the date object of the datebox to the remote filter rules?


Title: Re: DataGrid Filter Row - Use remote datebox filter with the Date as long value?
Post by: jarry on July 02, 2014, 12:11:42 AM
You can override the 'filterStringify' function to define how to stringify the 'filterRules' parameter value before sending the filter request to server.
Code:
$('#dg').datagrid({
filterStringify: function(data){
$.map(data, function(item){
if (item.field == 'changeDate'){
item.value = Date.parse(item.value);
}
});
return JSON.stringify(data);
}
})


Title: Re: DataGrid Filter Row - Use remote datebox filter with the Date as long value?
Post by: Stefan B. on July 02, 2014, 05:04:14 AM
Sorry but the datebox used an user defined formatter and parser to show the date in datagrid, formated in german style.
In oure example that is the geman formated date "02.07.2014"

But then the filter use the value extend from combo component. And this is in language specific format.
But the javascript function Date.parse(value) can only use the dateString as a string representing an RFC2822 or ISO 8601 date format.

I mean there should be a way to configure the filter of type datebox to return the value string or the intenal calender date object!
Then it is flexible.


Title: Re: DataGrid Filter Row - Use remote datebox filter with the Date as long value?
Post by: jarry on July 02, 2014, 08:11:30 AM
Please use $.fn.datebox.defaults.parser function to parse a Date object instead.
Code:
$('#dg').datagrid({
filterStringify: function(data){
$.map(data, function(item){
if (item.field == 'changeDate'){
item.value = $.fn.datebox.defaults.parser(item.value).getTime();
}
});
return JSON.stringify(data);
}
})
Another solution to solve your issue is to convert these values in your server side.


Title: Re: DataGrid Filter Row - Use remote datebox filter with the Date as long value?
Post by: Stefan B. on July 02, 2014, 11:49:13 PM
Thank you for your support. This works very well.
I also test the way to convert the date on server side.
Both works.