PDA

View Full Version : dateFormat issue



sidd
13 Sep 2009, 11:50 PM
Hi,


I am having a editor grid showing data fetched from database ..... it has some date field .... I am using a renderer in the columnModel for the date to format it in a proper manner. Its showing the data properly .... I am also having a from to insert data .....

when i am trying to insert data using the form ... it is making the request to the server but the data is not coming in the grid and i am getting an error ...... dateFormat is not a function .


I am using


function formatDate(value){
return value ? value.dateFormat('M d, Y') : '';
}as a renderer.

Any idea .... what is the issue ??

Thanks,
Sidd

Animal
14 Sep 2009, 12:48 AM
Well because the Field does not contain a Date object. You have to convert it to be a date, it's not magic.

sidd
14 Sep 2009, 1:55 AM
Hi,


I did it ..... I checked the date object with the Ext.isDate() function ....... if the value coming is a String then i converted it to Date and then parsed it ....

It resolved the error .... but now i am getting another error ..

Date.monthNames[c] is undefined

Any idea ?

Thanks,
Sidd

Condor
14 Sep 2009, 1:58 AM
What is the date format that your server sends and how did you configure your field for that?

sidd
14 Sep 2009, 9:15 PM
Thanks all for ur reply.

The issue has been solved.

Thanks,
Sidd

Estefan
14 Sep 2009, 10:26 PM
Hi.It will be better if you post your solution so that you will help those who have the same problem.

Thanks in advance

sidd
16 Sep 2009, 1:53 AM
Hi,

U r rite Estefan, The issue was not fixed... it was a dirty quick fix, That's why i didn't post it here.

What i did ...... if the value coming is not a date object ... then i am taking it as String and handling it in the server side ......



function formatDate(value){
if(value !=""){
if(Ext.isDate(value)){
return value.dateFormat('M d, Y');
}else{
return value;
}
}
return value;
}


Thanks & Regards,
Sidd

Condor
16 Sep 2009, 2:09 AM
Wrong solution.

You should have configured your field as:

{name: 'myfield', type: 'date', dateFormat: 'YmdHis'}
(use a dateFormat that matches your server format)
and your column as:

{header: 'My Field', dataIndex: 'myfield', renderer: Ext.util.Format.dateRenderer('M d, Y')}
(optionally using your original renderer to handle empty dates)

sidd
16 Sep 2009, 2:36 AM
Hi Condor,

Thanks for ur comment ..... But i dont have an issue with showing the date in the grid .... The issue is there when i am trying to add a record to the Grid ... I have a from to add record in the grid .... when i am submitting the data ..... the data getting submitting as a String for the date fields also.

It is able to make the server request properly but ..... but it is not able to put the data in the grid .... bcoz .... its getting error in dateFormat ...

After that I changed the code of my renderer. Checked, the coming objetc is a String or a date ... if its a String then i converted it to Date ... but it was not working .. got an error ..
Date.monthNames[c] is undefined

#renderer

function formatDate(value){
if(value !=""){
if(Ext.isDate(value)){
return value.dateFormat('M d, Y');
}else{
var dt = new Date(value);
alert(Ext.isDate(dt));
return dt.dateFormat('M d, Y');
}

}
return value;
}

#one grid field in reader

{name :'cer_end_date', mapping: 'cer_end_date', type: 'date',dateFormat: 'd/m/Y'}

#grid column for the field

{dataIndex :'cer_end_date',header : "CER End Date",width : 100,sortable : true,renderer: formatDate}

#form field

{fieldLabel: 'CER End Date',name : 'cer_end_date',xtype: 'datefield'}

Thanks,
Sidd

Condor
16 Sep 2009, 3:16 AM
What format is your server using to send dates?

And you are also adding records yourself? How do you create those records?

sidd
16 Sep 2009, 3:43 AM
What format is your server using to send dates?

And you are also adding records yourself? How do you create those records?



Hi,

date format coming from server is d/m/Y

I am not adding record myself .... i am using editor grid panel ....
and i am having a form to add the data.

#onCreate

onCreate : function(btn, ev) {
if (!this.getForm().isValid()) {
App.setAlert(false, "Form is invalid");
return false;
}
this.fireEvent('create', this, this.getForm().getValues());
this.getForm().reset();
}

#listener of form


listeners: {
create : function(fpanel, data) {
var rec = new currentStore.recordType(data);
currentStore.insert(0, rec);
currentGrid.startEditing(0, 1);
}
}


Thanks,
Sidd

Condor
16 Sep 2009, 4:06 AM
So the problem is that this.getForm().getValues() doesn't always return correct values for the record!

Have you tried using this.getForm().getFieldValues()?

Or, if that doesn't work, modify the values before you create a record from it?

sidd
23 Sep 2009, 2:07 AM
So the problem is that this.getForm().getValues() doesn't always return correct values for the record!

Have you tried using this.getForm().getFieldValues()?

Or, if that doesn't work, modify the values before you create a record from it?



Thanks Condor ,

this.getForm().getFieldValues() solved my problem ...

Thanks,
Sidd