1. #1
    Sencha Premium Member Springvar's Avatar
    Join Date
    Oct 2010
    Location
    Trondheim, Norway
    Posts
    4
    Vote Rating
    0
    Springvar is on a distinguished road

      0  

    Default Configurable submitFormat on date fields in JsonStore

    Configurable submitFormat on date fields in JsonStore


    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?
    Code:
     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:
    Code:
     {
      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
     }
    Also posted on StackOverflow: http://stackoverflow.com/questions/3...unix-timestamp

  2. #2
    Sencha Premium Member Springvar's Avatar
    Join Date
    Oct 2010
    Location
    Trondheim, Norway
    Posts
    4
    Vote Rating
    0
    Springvar is on a distinguished road

      0  

    Default Manipulate the post params in the HttpProxy event beforewrite

    Manipulate the post params in the HttpProxy event beforewrite


    I know this case is old, but I found a solution to this problem that I never came around to post here.

    I added a listener to the proxy's beforewrite event, and manipulated the post params there
    Code:
     proxy: new Ext.data.HttpProxy({
      api: {
       create: '/create/',
       read:   '/read/',
       update: '/update/',
       destroy:'/destroy/'
      },
      listeners: {
       beforewrite: function(proxy, action, record, params) {
        var fromTs = record.data.fromTs;
        var toTs = record.data.toTs;
    
        if(record.data.fromTs) record.data.fromTs = fromTs.format('U');
        if(record.data.toTs) record.data.toTs = toTs.format('U');
    
                    // Update record to be sent
        // root = store.reader.root
        params.root = Ext.util.JSON.encode(record.data);
    
        // Restore record
        record.data.fromTs = fromTs;
        record.data.toTs = toTs;
       }
      }
    })
    Last edited by Springvar; 18 Mar 2011 at 4:55 AM. Reason: Preview equals post in this forum... I still need to edit

Similar Threads

  1. XDateField with configurable submitFormat
    By jsakalos in forum Ext 2.x: User Extensions and Plugins
    Replies: 77
    Last Post: 10 Dec 2013, 4:55 AM
  2. DateField: displayFormat VS submitFormat
    By tobiu in forum Ext 3.x: Help & Discussion
    Replies: 6
    Last Post: 11 Feb 2010, 9:35 AM
  3. XTimeField with configurable submitFormat
    By jsakalos in forum Ext 2.x: User Extensions and Plugins
    Replies: 2
    Last Post: 6 Jul 2009, 5:50 AM
  4. Replies: 5
    Last Post: 20 May 2008, 6:13 PM

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi