PDA

View Full Version : Update datefield from a Grid



msinn
24 Sep 2009, 8:50 AM
Hello everybody,

I've tried to find an answer to my problem, but unfortunately it wasn't the best day.

My date in the GroupingStore, as the server sent it:


{
name : 'startdate',
type : 'date',
dateFormat : 'd.m.Y'
},My date in the EditorGridPanel:


{
//xtype : 'datecolumn',
header : 'Start',
dataIndex : 'startdate',
//format : 'd.m.Y',
width : 80,
sortable : true,
renderer : Ext.util.Format.dateRenderer('d.m.Y'),
editor : {
xtype : 'datefield',
format: 'd.m.Y',
allowBlank : false,
minValue : '01.01.2009',
minText : 'Text',
maxValue : (new Date()).format('d.m.Y'),
maxText : 'Text'
}
},So I update the grid:


listeners : {
afteredit : function(e) {
var conn = new Ext.data.Connection();
conn.request({
url : 'database/updateEmployee.php',
params : {
hbe_id : e.record.data.hbe_id,
field : e.field,
value : e.value
},
success : function(resp, opt) {
e.record.commit();
},
failure : function(resp, opt) {
e.record.reject();
}
});
}
},The problem is that the changed date is sent in row format (please see the attachement), but the server waits on the same format as it sent it.

Could you please show me were I do the mistake?

Thanks a lot

Marius

msinn
24 Sep 2009, 11:13 PM
Nobody can answer hier such an easy question?
How to convert de Date object into the string format d.m.Y with Ext JS before I sent it to the server? So difficult? :-/

Is this forum for beginners not allowed?

Have a nice day

jarlau
25 Sep 2009, 12:10 AM
use Ext.util.Format.date(e.value, 'Y-m-d')

msinn
25 Sep 2009, 1:28 AM
Thank you a lot jarlau! =D>

The problem is that I do not have just date fields, so first I must check if the event contains a date object.
I've tried as bellow but I get an error in firebug:

isDate(e)... is not defined

I'm trying to learn Ext JS, so please, please, please tell me how to solve this problem.


listeners : {
afteredit : function(e) {
var conn = new Ext.data.Connection();
conn.request({
url : 'database/updateEmployee.php',
params : {
hbe_id : e.record.data.hbe_id,
field : e.field,
//value : e.value
value : isDate(e) ? Ext.util.Format.date(e.value, 'd.m.Y') : e.value
},
success : function(resp, opt) {
e.record.commit();
},
failure : function(resp, opt) {
e.record.reject();
}
});
}
},Thank you again jarlau

jarlau
25 Sep 2009, 1:43 AM
try Ext.isDate(Date.parseDate(e.value))

Nagadev
25 Sep 2009, 1:47 AM
is e.value represents startdate 's value ?
I dont think so, you can try e.record.data.startdate

msinn
25 Sep 2009, 4:41 AM
@jarlau thank you for your help again
I've tried so this time:


listeners : {
afteredit : function(e) {
var conn = new Ext.data.Connection();
conn.request({
url : 'database/updateEmployee.php',
params : {
hbe_id : e.record.data.hbe_id,
field : e.field,
//value : e.value
value : Ext.isDate(Date.parseDate(e.value)) ? Ext.util.Format.date(e.value, 'd.m.Y') : e.value //row 274
},
success : function(resp, opt) {
e.record.commit();
},
failure : function(resp, opt) {
e.record.reject();
}
});
}
},but this error in firebug


m is undefined
anonymous() ext-all.js (Zeile 7)
anonymous() ext-all.js (Zeile 7)
anonymous() row-editor.js (Zeile 274)
anonymous() ext-all.js (Zeile 7)
anonymous() ext-base.js (Zeile 7)
anonymous() ext-all.js (Zeile 7)
anonymous() ext-all.js (Zeile 7)
anonymous(Object field=Object initialConfig=Object events=Object, Tue Sep 08 2009 00:00:00 GMT+0200, Object type=date dateFormat=d.m.Y value=01.01.1940) ext-all.js (Zeile 11)
anonymous() ext-all.js (Zeile 7)
anonymous() ext-all.js (Zeile 7)
anonymous([Object scope=Object options=Object 0=Object], function(), Object name=E) ext-base.js (Zeile 7)
anonymous() ext-all.js (Zeile 7)
anonymous() ext-all.js (Zeile 7)
anonymous(Object name=a) ext-all.js (Zeile 7)
anonymous() ext-all.js (Zeile 7)
anonymous() ext-all.js (Zeile 7)
anonymous([Object scope=Object options=Object 0=Object], function(), Object name=E) ext-base.js (Zeile 7)
anonymous() ext-all.js (Zeile 7)
anonymous() ext-all.js (Zeile 7)
anonymous() ext-all.js (Zeile 11)
anonymous() ext-all.js (Zeile 11)
anonymous(Object browserEvent=Event mousedown button=0) ext-all.js (Zeile 11)
y() ext-all.js (Zeile 7)
anonymous() ext-all.js (Zeile 7)
[Break on this error] Ext.DomHelper=function(){var s=null,j=/^...b.stopEvent();this.completeEdit()}}}});\n ext-all.js (Zeile 7)@Nagadev
Thank you for your answer

the e.value is for each field of the record. After editing a field the new value of the field is sent to the server. It works good, just when I edit data fields another date format is sent to the server as 'd.m.Y'.(see attachement above)

Do you have any idea how to convert this date format with Ext JS before sending it to the server?

Thank you all

jarlau
25 Sep 2009, 6:06 PM
no need to use Date.parseDate(), just


value : Ext.isDate(e.value) ? Ext.util.Format.date(e.value, 'd.m.Y') : e.value

should work.

msinn
28 Sep 2009, 2:33 AM
It works \:D/,

thank you jarlau, you are my first best helper.

I whish you the best week

Marius