EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: phunksta on October 24, 2014, 10:36:42 AM



Title: datebox and datetimebox with edatagrid, formatting and parsing
Post by: phunksta on October 24, 2014, 10:36:42 AM
Hi, hope someone can help, I have a head-shaped depression in the wall by my desk!

Please see this fiddle: http://jsfiddle.net/phunksta/4uf1cnvv/1/ (http://jsfiddle.net/phunksta/4uf1cnvv/1/)

My data is returned in ISO format, I use column formatter to call the custom formatter of the datetimebox to display the values before editing.
On edit, the date is parsed OK
On opening the datebox calendar, the current date is selected - I'm ok with this, but strangely the parser was called during this process!
Now, on selecting a date, the datetimebox parser is called again, but on a formatted versions of the value, not the original or newly selected!

Can anyone help me get this round-trip working?

Thanks!


Title: Re: datebox and datetimebox with edatagrid, formatting and parsing
Post by: stworthy on October 25, 2014, 04:26:41 AM
Please try the updated example http://jsfiddle.net/4uf1cnvv/2/


Title: Re: datebox and datetimebox with edatagrid, formatting and parsing
Post by: phunksta on October 27, 2014, 06:18:41 AM
Thanks again stworthy!

I can see that works nicely, but I think that is because the data format and display format are now the same (ISO) format, so easyui datebox is now happy.

I was trying to maintain this format for data storage and interchange with the controller, but for the View to be able to apply a localised format. Is this possible with a datebox?

Edit: is it also possible to allow NULL date value handling with easyui, as trying to allow null values results in them being replaced with today's date in most cases. When I try to override to allow nulls, the easyui code fails because date functions can't be called on the null values :(


Title: Re: datebox and datetimebox with edatagrid, formatting and parsing
Post by: stworthy on October 27, 2014, 08:11:25 AM
You can override the 'formatter' and 'parser' function to customize the date format. Please refer to the following example.
http://jsfiddle.net/yrc30nwe/


Title: Re: datebox and datetimebox with edatagrid, formatting and parsing
Post by: phunksta on October 27, 2014, 11:06:13 AM
Hi, OK we are now back to where I started  ;)

So my problem is that when I override formatter and parser to implement localised format, this stops working when used as an edatagrid editor.

The reason seems to be the dataflow:

1) The data value in ISO format goes through 'formatter' and is changed to localised format
2) The editor is opened, the value goes through 'parser' which fails because it expects ISO format, but received localised format
3) Now using a parser that works with either format, I can get further, but now 'saveRow' of edatagrid is picking up localised format, and sending this to the controller.
4) Controller fails as it expected ISO format.

What I seem to need, is a 'datebox' and 'datetimebox' control, that keeps data in ISO format at all times, but displays in localised format.
I know that combo's generally have a textfield (added on init) and a valuefield (the original input element) - could I intercept the value going back and forward between these somehow?

I have gotten so far by overrides - the last piece of the puzzle seems to be ensuring that ISO format is re-established before 'saveRow'.
The next problem is now performance: As my formatter and parser become more complicated having to determine which format is currently being processed, the overall performance of datagrid goes downward. This isn't helped by the fact that these functions seems to be called 2-3 times per event.


Title: Re: datebox and datetimebox with edatagrid, formatting and parsing
Post by: stworthy on October 27, 2014, 05:38:31 PM
If you only want to post the locale formatted date to your server, try to use 'loadFilter' function to transfer the original data to desired format.
http://jsfiddle.net/4uf1cnvv/3/


Title: Re: datebox and datetimebox with edatagrid, formatting and parsing
Post by: phunksta on October 29, 2014, 03:51:48 AM
Hmm ok interesting...

So bulk process on the way in, and I guess on the way out too.
or I guess I will have to look to do a custom datebox that retains server/local format.

Thanks for your help!