View Full Version : Remove Day of the Week from Date Picker

4 Oct 2006, 12:47 PM
How do I remove the day of the week from the output of the date picker?

4 Oct 2006, 1:31 PM
What do you mean "the output"? Do you mean remove it from the UI?

4 Oct 2006, 7:53 PM
I have added a column that uses the date editor. I have the date editor set with the following values:

editor: new yg.DateEditor({format: 'MM/dd/yyyy', minValue: '01/01/06'})

Once the date picker appears, I select a date (e.g. 10/04/2006) and the grid shows the date formatted just like above. However once I tab off the cell the date format changes to Thu Oct 05 2006 00:00:00 GMT-0400 (Eastern Daylight Time). How do I set the grid so the date reflects the format set above?

5 Oct 2006, 12:28 AM
There's an editor and a renderer, both are defined independently. Renders handle formating values in cells (when not in editing mode) and obviously editors are for editing.

Here's the JS file for the editor grid example:


There is a function defined in the local scope:

var formatDate = function(value){
return value.dateFormat('M d, Y');

Add the column definition looks like this:

header: "Available",
width: 95,
renderer: formatDate,
editor: new yg.DateEditor({
format: 'm/d/y',
minValue: '01/01/06',
disabledDays: [0, 6],
disabledDaysText: 'Plants are not available on the weekends',
disabledDates : ['^07', '04/15', '12/02/06'],
disabledDatesText : 'The plants are pollinating on %0, choose a different date.'})

Notice the renderer config option. This defines the function to call to provide custom formatting of the cells value.

Both date formats could be the same, in the example I just wanted to show they didn't have to be.

5 Oct 2006, 10:14 AM

Thanks for the help. I started using the formatDate code listed above in my grid but I am getting a javascript error saying ""value.dateFormat is not a function". I am including the date-util.js script in my web page.

Here is the code from my page:

<title>GTD - Denis Mayer</title>

#editor-grid .ygrid-col-3{







Am I missing anything?[/code]

5 Oct 2006, 11:54 AM

I found the problem. The formatDate function needs an additional line in order to work correctly:

Original formatDate Code:

var formatDate = function(value){
return value.dateFormat('M d, Y');

New Code

var formatDate = function(value){
var d = new Date(value);
return d.dateFormat('m/d/Y');

When I ran the original code I was getting a javascript error saying that "dateFormat doesnt exist". By declaring a date variable set to value parameter the issue goes away.


5 Oct 2006, 12:00 PM
The forum seems to have stripped all your code.

You don't need to include the date-util.js script, there is a small library included by default in yutil.js, which is part of yui-ext-core.js (and in yui-ext.js too if you are including everything).

How are you loading your data? Is it from an array, an XMLDataModel, ... ? The "dateFormat" function is defined on all Date objects. My guess is that it the internal data isn't a date object. For example, if you are using XML, you should parse the date using a preprocessor function. This way it's sorted, edited and rendered from the same date object instead of being parsed repetitively. Since you are using an editor, it's also logical that you would like changes reflected in your XML document. This is where you can provide a postProcessor function to convert the date back to a string before it is stored back in the XML file.

If you look at the script in the link I included in my last message, it is doing just that:

var parseDate = function(value){
return new Date(Date.parse(value));
dataModel.addPreprocessor(3, parseDate);

A post processor would be the same, only in reverse:

var formatXmlDate = function(value){
return value.format('m/d/y');
dataModel.addPostprocessor(3, formatXmlDate);

Manually doing this is kind of a pain and in a future version it would make sense to introduce data types that do this for you automatically.

5 Oct 2006, 1:14 PM
I am using PHP, MySQL and the yahoo-ext grid.

The grid is calling a php file to get the rows in JSON format. So naturally, I'm using the JSONDataModel to load the grid.

When I do that, the dates are coming back as strings which is why I'm casting them to a date.

5 Oct 2006, 1:42 PM
Same thing with the JSONDataModel, add the preprocessor function some you don't parse them every time you do something with it.