Search code examples
extjsextjs4extjs4.2

Search a data in table using datepicker in extjs


I created a table where I need to sort the values using the dates, so I used the datepicker but its not working how to sort the data using the date picker.
The exact output is if i select the date "17-09-01" I need to get the columns which have these dates. once if i given some date on textbox, based on textbox value I need to filter related records from all columns. Can you tell me how to achieve? What change I need to do? You can view my code in Fiddle


Solution

  • I have made following changes to your code to make it work.

    1. In a model, specify the date field properly with dateFormat.

                      {
                          name: 'date',
                          type: 'date',
                          dateFormat: 'y-m-d'
                      }
      
    2. In a grid, better use datecolumn with format property.

               {
                  //Use xtype datecolumn for dates and specify the format
                  xtype: 'datecolumn',
                  text: 'Date',
                  dataIndex: 'date',
                  flex: 2,
                  format: 'y-m-d'
              }
      
    3. Avoid using storeId on store, though you had not specified it but were trying to retrieve store by it.

              handler: function (picker, date) {
                //var store = Ext.getStore('storeId');
                var store = picker.up('#myGridItemId').getStore();
                // clear current filters
                store.clearFilter();
               // filter store
               var date = Ext.first('#selectedDate').getValue();
               store.filter("date", date);
              }
      
    4. Here's the modified code. Read my comments for more.