views:

48

answers:

1

I use an editorgrid to edit elements from a JsonStore. The JsonStore uses a HttpProxy to update the backend database.

My problem is that the backend API expects fromTs and toTs to be Unix timestamps, but when a record is updated, the resulting http post contains a date formatted like this: Wed Oct 20 00:00:00 UTC+0200 2010

I've searched the API documentation for a parameter to control the post format, but I've not been able to find anything. Is there a simple way to do this?

 myJsonStore = new Ext.data.JsonStore({
  autoLoad: true,
  autoSave: true,
  proxy: new Ext.data.HttpProxy({
   api: {
    create: '/create/',
    read: '/read/',
    update: '/update/',
    destroy:'/destroy/'
   }
  }),
  writer: new Ext.data.JsonWriter({
   encode: true,
   writeAllFields: true
  }),
  idProperty: 'id',
  fields: [
   {name: 'id',  type: 'int'},
   {name: 'fromTs', type: 'date', dateFormat:'timestamp'},
   {name: 'toTs',  type: 'date', dateFormat:'timestamp'}
  ]
 });

The editorgrid is configured like this:

 {
  xtype: 'editorgrid',
  clicksToEdit: 1,
  columns: [
         {header: "Id", dataIndex: 'id', editable: false},
   {header: "From", dataIndex: 'fromTs', editor: new Ext.form.DateField({format: 'd.m.Y', startDay: 1}), xtype: 'datecolumn', format: 'd.m.Y'},     
   {header: "To", dataIndex: 'toTs', editor: new Ext.form.DateField({format: 'd.m.Y', startDay: 1}), xtype: 'datecolumn', format: 'd.m.Y'}
  ],
  store: myJsonStore
 }
A: 

You might be able to hook into the validateedit event or afteredit event of your EditorGridPanel and convert the user-entered-value back into a timestamp using a Date parsing method. I'm guessing that EditorGridPanel is updating the records in the store verbatim without converting them back into timestamps, so you have to do that manually. So I'm thinking maybe something like:

grid.on('validateedit', function(event) {
  if (isDateColumn(column)) {
    event.record.data[event.field] = dateToTimestamp(event.value);
  }
}
Kenny Peng
Unfortunately this does not work. It seems like date fields uses this date format for internal storage regardless of format parameters. When I set the value to a timestamp, the date field will resolve this as an invalid date. The json post will still contain the unwanted date format. `{"id":"6","fromTs":"2010-10-12T00:00:00","toTs":"NaN-NaN-NaNTNaN:NaN:NaN"}`
Ivar Bonsaksen
Your only option in that case might be then to override some of the behavior in `doResponse()` and create the POST with your own parameters, formatted.
Kenny Peng