Hi,
So, after I replied to your question, I looked over my code and
realized that using the altFormat was not the best way to do this (to
use one format from the datasource and another to show), and was in
fact causing a bug in my code. I hope I didn't throw you too far off
with that. However, I think I have a solution, which I'll cut and
past below. (I haven't tested this too much yet, but I think its the
right path)
Basically, the way this works is to define a formatter, for converting
the date from source format to the format we want to display (I'll
call this show format). Then, we also define an editor which converts
from source format to show format when loading data, and from show
format to source format when putting it back (serializing it). The
formats are defined in the coumn definitions, using an attribute
ShowDateFormat and SourceDateFormat.
Here's an example of the column definition part:
{id:"hiredate" , name:"hiredate" , field:"hiredate" , width:"120" ,
formatter: DateCellFormatter,
editor: DateCellEditor2 , DateSourceFormat: "yy-mm-dd" ,
DateShowFormat: "mm/dd/yy" },
Now, here's the formatter part that I used (add to the similar looking
parts in slick.editors.js)
DateCellFormatter : function(row, cell, value, columnDef,
dataContext){
if(value != '0000-00-00'){
var thedate = $.datepicker.parseDate(columnDef.DateSourceFormat,
value);
return $.datepicker.formatDate( columnDef.DateShowFormat,
thedate );
}else{
return '';
}
},
And, heres the part I used for an editor (DateCellEditor2). Most is
the same as DateCellEditor.
DateCellEditor2 : function(args) {
var $input;
var defaultValue;
var scope = this;
var calendarOpen = false;
var showFormat = "yy-mm-dd";
var sourceFormat = "yy-mm-dd";
this.init = function() {
if(args.column.DateSourceFormat != undefined){
sourceFormat = args.column.DateSourceFormat;
}
if(args.column.DateShowFormat != undefined){
showFormat = args.column.DateShowFormat;
}
$input = $("<INPUT type=text class='editor-text' />");
$input.appendTo(args.container);
$input.focus().select();
$input.datepicker({
showOn: "button",
beforeShow: function() { calendarOpen = true },
onClose: function() { calendarOpen = false },
dateFormat: showFormat
});
$input.width($input.width() - 18);
};
this.destroy = function() {
$.datepicker.dpDiv.stop(true,true);
$input.datepicker("hide");
$input.datepicker("destroy");
$input.remove();
};
this.show = function() {
if (calendarOpen) {
$.datepicker.dpDiv.stop(true,true).show();
}
};
this.hide = function() {
if (calendarOpen) {
$.datepicker.dpDiv.stop(true,true).hide();
}
};
this.position = function(position) {
if (!calendarOpen) return;
$.datepicker.dpDiv
.css("top", position.top + 30)
.css("left", position.left);
};
this.focus = function() {
$input.focus();
};
this.loadValue = function(item) {
defaultValue = item[args.column.field];
var thedate = $.datepicker.parseDate(sourceFormat, defaultValue);
defaultValue = $.datepicker.formatDate( showFormat, thedate );
$input.val(defaultValue);
$input[0].defaultValue = defaultValue;
$input.select();
};
this.serializeValue = function() {
var thedate = $.datepicker.parseDate(showFormat, $input.val());
return $.datepicker.formatDate( sourceFormat,
thedate );
};
this.applyValue = function(item,state) {
item[args.column.field] = state;
};
this.isValueChanged = function() {
return (!($input.val() == "" && defaultValue == null))
&& ($input.val() != defaultValue);
};
this.validate = function() {
return {
valid: true,
msg: null
};
};
this.init();
},
Sorry to throw you off the first time, but I hope this might help!
-Chris
> > If this doesn't quite give the format you want, tryhttp://
docs.jquery.com/UI/Datepicker/formatDatefordate format