Results 1 to 8 of 8

Thread: Remote filtering set date filter as date is rendered, not as is read from proxy

  1. #1
    Sencha User Fire-Dragon-DoL's Avatar
    Join Date
    Dec 2011
    Posts
    141
    Answers
    9

    Default Answered: Remote filtering set date filter as date is rendered, not as is read from proxy

    I'm having a problem because I read a date in my model from a json with format YEAR-MONTH-DAY

    Then I render it in DAY/MONTH/YEAR format, however when I filter (remote, by date) my store, instead of obtaining in the filter a date formatted as YEAR-MONTH-DATE I obtain it as a DAY/MONTH/YEAR.

    This is definitely a problem because I expect the date on the server format and not on the "view" format. Also, if I change the view format I have to change the server converter every time, which is horrible.

    Any suggestion on how to change this behaviour? Is this a bug?

  2. I solved by myself by setting on the column these settings (notice expecially the filter settings):
    Code:
        {
          header: 'Data di nascita',
          dataIndex: 'birth_date',
          renderer : Ext.util.Format.dateRenderer('d/m/Y'),
          editor: {
            allowBlank: true,
            xtype: 'datefield',
            format: 'd/m/Y'
          },
          filter: {
            dateFormat: 'Y-m-d'
          }
        }

  3. #2
    Sencha User Fire-Dragon-DoL's Avatar
    Join Date
    Dec 2011
    Posts
    141
    Answers
    9

    Default

    This is quite important, I wrote the code to convert back the data but now I'm looking forward a function that is fired right before filtering to allow a pre-conversion before filter is sent to the server. Are there any possibility?

  4. #3
    chramer's Avatar
    Join Date
    Feb 2011
    Location
    Chisinau, Moldova
    Posts
    316
    Answers
    64

    Default

    interesting..
    show us the model and the columns!

  5. #4
    Sencha User Fire-Dragon-DoL's Avatar
    Join Date
    Dec 2011
    Posts
    141
    Answers
    9

    Default

    Model:
    Code:
    Ext.define('FedertrekDesktop.model.PersonalRecord', {
      extend: 'Ext.data.Model',
    
      proxy: {
        type: 'railsrest',
        url: '/personal_records',
        format: 'extjson',
        reader: {
          type: 'json',
          root: 'root'
        },
        writer: {
          type: 'json'
        }
      },
    
      fields: [
        {
          name: 'id',
          type: 'int'
        },
        {
          name: 'name',
          type: 'string'
        },
        {
          name: 'surname',
          type: 'string'
        },
        {
          name: 'birth_date',
          type: 'date',
          dateFormat: 'Y-m-d'
        },
        {
          name: 'birth_place',
          type: 'string'
        },
        {
          name: 'residence',
          type: 'string'
        },
        {
          name: 'email',
          type: 'string'
        },
        {
          name: 'mobile_phone',
          type: 'string'
        },
        {
          name: 'phone',
          type: 'string'
        }
      ],
    
      idProperty: 'id'
    
    });
    Window with grid and columns:
    Code:
    Ext.define('FedertrekDesktop.view.personalrecords.Window', {
      extend: 'FedertrekDesktop.view.desktopwindow.BaseDesktopWindow',
      alias : 'widget.personalrecordswindow',
    
      width: 800,
      height: 400,
      layout: 'fit',
    
      initComponent: function() {
        var me = this;
    
        var gridColumns   = [
        {
          header: '#',
          dataIndex: 'id',
          editor: null,
          hidden: true
        },
        {
          header: 'Nome',
          dataIndex: 'name',
          editor: {
            xtype: 'textfield',
            allowBlank: true
          }
        },
        {
          header: 'Cognome',
          dataIndex: 'surname'
        },
        {
          header: 'Data di nascita',
          dataIndex: 'birth_date',
          renderer : Ext.util.Format.dateRenderer('d/m/Y'),
          editor: {
            allowBlank: true,
            xtype: 'datefield',
            format: 'd/m/Y'
          }
        },
        {
          header: 'Luogo di nascita',
          dataIndex: 'birth_place'
        },
        {
          header: 'Residenza',
          dataIndex: 'residence'
        },
        {
          header: 'E-Mail',
          dataIndex: 'email',
          editor: {
            vtype: 'email'
          }
        },
        {
          header: 'Cellulare',
          dataIndex: 'mobile_phone'
        },
        {
          header: 'Telefono',
          dataIndex: 'phone'
        }];
    
        var itemsGrid = Ext.create('Fdd.grid.XPanel', {
          grouping: {
            groupHeaderTpl: '{name} ({rows.length})'
          },
          columns: {
            items: gridColumns
          },
          store: 'PersonalRecords',
          firstColumnToEdit: 1
        });
    
        Ext.apply(me, {
          items: [itemsGrid]
        });
    
        me.callParent(arguments);
      }
    
    });
    Notice that I'm inheriting from different classes because I added functionalities (row editing, filtering and things like that) but I don't think you need that code. These are my columns and my fields.
    As you can see I have a renderer but I read from a different format.
    However when data is sent to my filter, I get the renderer format instead of the server format. I think this is not a logical choice, expecially because enforce you a double conversion when a renderer should be... a renderer.

  6. #5
    chramer's Avatar
    Join Date
    Feb 2011
    Location
    Chisinau, Moldova
    Posts
    316
    Answers
    64

    Default

    Try to add this to your code:
    Code:
        
    {
          header: 'Data di nascita',
          xtype: 'datecolumn',
          dataIndex: 'birth_date',
          renderer : Ext.util.Format.dateRenderer('d/m/Y'),
          editor: {
            allowBlank: true,
            xtype: 'datefield',
            format: 'd/m/Y'
          }
    }
    If it doesn't work, show us how you send your data to the filter...

  7. #6
    Sencha User Fire-Dragon-DoL's Avatar
    Join Date
    Dec 2011
    Posts
    141
    Answers
    9

    Default

    It doesn't change anything:
    Code:
    filter[{"type":"date","comparison":"lt","value":"05/28/2012","field":"birth_date"}]
    By the way, I think the problem is directly connected with filters, not with column type.
    In fact, I tried by changing the type of mobile_phone column into number column and is correctly displayed as a number, however the filter is still a string.

    Most important, I have a date filter on the date column, the problem is that is not formatted as I want so maybe there should be an option for date filter, not a problem of not being a date filter.

  8. #7
    Sencha User Fire-Dragon-DoL's Avatar
    Join Date
    Dec 2011
    Posts
    141
    Answers
    9

    Default

    I solved by myself by setting on the column these settings (notice expecially the filter settings):
    Code:
        {
          header: 'Data di nascita',
          dataIndex: 'birth_date',
          renderer : Ext.util.Format.dateRenderer('d/m/Y'),
          editor: {
            allowBlank: true,
            xtype: 'datefield',
            format: 'd/m/Y'
          },
          filter: {
            dateFormat: 'Y-m-d'
          }
        }

  9. #8
    Sencha Premium Member
    Join Date
    Nov 2011
    Location
    Compiegne FRANCE
    Posts
    48

    Default

    Hello,

    Same issue and same solution.
    Thank you for the answer.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •