[CLOSED] dynamic date filter not working

  1. #1

    [CLOSED] dynamic date filter not working

    I have added dynamic filter to grid which is dynamically created as below:
     DateFilter df = new DateFilter();
                    df.DataIndex = "MONTH_YEAR";
                    df.DatePickerOptions.TodayText = "Now";
                    df.Format = "MMM-yy";
                    gf.Filters.Add(df);
    I am binding the model field to store as :

      model.Fields.Add(new ModelField("MONTH_YEAR"));
    the date format it displays as : Aug-13, May-13

    But when i use the filter no record shows up. What am i missing.

    Also how do i customize the filter to only show Months on the date picker

    Thanks in advance
    Last edited by Daniil; Aug 15, 2013 at 10:35 AM. Reason: [CLOSED]
  2. #2
    Hi @PriceRightHTML5team,

    I think you should set up Type.Date for the ModelField.
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @PriceRightHTML5team,

    I think you should set up Type.Date for the ModelField.
    I did that but still its not working . The date format i am showing on the grid is "MMM-yy"
    so it show as "Aug-13","Sept-13","Oct-13"... and so on.

    How do i customize the filter so that it filters records based on this format
  4. #4
    Please provide a full test case.
  5. #5
    Quote Originally Posted by Daniil View Post
    Please provide a full test case.
    @( X.Panel().Collapsed(false).ID("pnlPriceTrendTabular")
    
                    .Height(400)
                     .DefaultAnchor("100%")
                    .Layout(LayoutType.Fit)
                    .AutoScroll(true)
                    .Control(item => this.Initchart(item))
    
             )
    Below is the MVC code

    @functions{
     private void Initchart(Panel pnlGrafico)
        {
      Ext.Net.GridPanel grid = new GridPanel()
            {
                ID = "gridSnapshotTab",
                Layout = "Container",
                Scroll = ScrollMode.Both,
                ForceFit = false,
                AutoScroll = true,
                ColumnLines = true,
                EmptyText = "No data found"
            };
    var result = svc.getData();
    
     Store store = new Store();
            store.ID = "StoreTabView";
            var model = new Model();
    
    model.Fields.Add(new ModelField("MONTH_YEAR",ModelFieldType.Date));
      model.Fields.Add(new ModelField("CountryName"));
    
          store.Model.Add(model);
            store.Data = result;
            store.LoadData(result);
    
       grid.Store.Add(store);
    
    grid.ColumnModel.Add(new DateColumn() {
                                Text = "Month",
                                DataIndex = "MONTH_YEAR",                         
                                Format = "MMM-yy"
                            });
      grid.ColumnModel.Add(new Column()
                    {
                        Text = "Country",
                        DataIndex = "CountryName"
                    });
    
       GridFilters gf = new GridFilters();
            gf.Local = true;
    
     DateFilter df = new DateFilter();
                    df.DataIndex = "MONTH_YEAR";
                    df.DatePickerOptions.TodayText = "Now";
                    df.Format = "MMM-yy";
                    //df.Type = FilterType.Date;
                    gf.Filters.Add(df);
     gf.Filters.Add(new StringFilter() { DataIndex = "CountryName" });
    grid.Features.Add(gf);      
           
            pnlGrafico.Items.Add(grid);
    }
    }
  6. #6
    Thank you.

    It appears to be working as expected for me.

    What are the steps to reproduce the issue using the test case?
  7. #7
    Quote Originally Posted by Daniil View Post
    Thank you.

    It appears to be working as expected for me.

    What are the steps to reproduce the issue using the test case?
    So when i select the date filter and filter it by selecting "Sept-13" (13 is the year 2013) it doesn not show up the record for that month.
    I need the filter to work for monthly basis. I think it is comparing the days .

    How can i configure to filter it by months since my grid displays "Aug-13","Sept -13" and so on
  8. #8
    So, there are three DateFields in the filter: Before, After and On. You are picking up a date in the On, right?
  9. #9
    Quote Originally Posted by Daniil View Post
    So, there are three DateFields in the filter: Before, After and On. You are picking up a date in the On, right?
    Yes. But even in Before and After its not working
  10. #10
    I understand the requirement now. There is no such functionality.

    You can override a DateFilter's validateRecord as needed.
    <ext:DateFilter DataIndex="date"  Format="MMM-yyyy">
        <ValidateRecord Fn="myCustomValidateRecord" />
    </ext:DateFilter>
    Here is the original function.
    validateRecord : function (record) {
        var key,
            pickerValue,
            val = record.get(this.dataIndex),
            clearTime = Ext.Date.clearTime;
    
        if(!Ext.isDate(val)){
            return false;
        }
        val = clearTime(val, true).getTime();
    
        for (key in this.fields) {
            if (this.fields[key].checked) {
                pickerValue = clearTime(this.getFieldValue(key), true).getTime();
                if (key == 'before' && pickerValue <= val) {
                    return false;
                }
                if (key == 'after' && pickerValue >= val) {
                    return false;
                }
                if (key == 'on' && pickerValue != val) {
                    return false;
                }
            }
        }
        return true;
    }

Similar Threads

  1. Gridpanel multiheader From To date filter
    By nomz in forum 2.x Help
    Replies: 4
    Last Post: Oct 26, 2012, 10:39 AM
  2. [CLOSED] GridPanel Column Filter - Date from-to ?
    By sisa in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 10, 2012, 1:20 PM
  3. Replies: 1
    Last Post: Apr 13, 2012, 1:52 PM
  4. Add date range grid filter
    By stone216 in forum 1.x Help
    Replies: 12
    Last Post: May 24, 2010, 5:32 PM
  5. [CLOSED] Date Filter in GridPanel
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 27, 2009, 10:27 AM

Tags for this Thread

Posting Permissions