#1 November 25, 2014 6:07pm

jmason03
Member
Registered: January 9, 2014
Posts: 123

Using a Parser with Dates

I'm not quite sure what the best approach is to accomplish what I want. Basically, I have a module where one of the fields is a date which is stored in the database as Y-m-d like it should be. However, I would prefer not display it that way to the user so I set up a simple parser in the view:
$date = new DateTime($value); $value = $date->format('m/d/Y');

This displays all the dates in the view correctly but the problem is that I also want to sort all the rows by this date. Since the parser affects all values in the view_cache table as soon as it's created/modified, when I select that column to be sorted my date values are now stored in the view_cache table using my parser date formats which doesn't work well with MySQL and the dates are instead sorted alphabetically (11/25/2014 comes after 01/01/2015).

Is there a way to keep values in the view_cache table from having the parser applied to them until they are loaded by the view? That way the displayed value in the results table would be aesthetically correct but the actual value would still be programmatically correct and sortable.

I do realize that this quite possibly defeats the purpose of the view_cache table since this setup would require running the parser each time. This isn't a super necessary feature, they'll still be able to read/understand the date regardless of which of the two formats is shown, I just wanted to ask.

Thanks

Offline

#2 November 26, 2014 2:34pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: Using a Parser with Dates

Unfortunately there isn't a way to keep both the original value and the parsed value in there, so sorting by your parsed column is always going to sort alphabetically. We would need something like a shadow column with the old data in there with an option to sort by that column when a user selects the parsed column. It's not a bad idea for a feature request though. Dates are definitely a good use case. If you think it's worth pursuing for 4.3 add it as an issue on GitHub -- we'll be doing a team regroup after the Thanksgiving break to hammer out what features will make 4.3.

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.