PDA

View Full Version : [CLOSED] dynamic date filter not working



PriceRightHTML5team
Aug 06, 2013, 5:03 AM
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

Daniil
Aug 06, 2013, 5:48 AM
Hi @PriceRightHTML5team,

I think you should set up Type.Date for the ModelField.

PriceRightHTML5team
Aug 06, 2013, 5:59 AM
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

Daniil
Aug 06, 2013, 8:33 AM
Please provide a full test case.

PriceRightHTML5team
Aug 06, 2013, 8:49 AM
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);
}
}

Daniil
Aug 06, 2013, 12:31 PM
Thank you.

It appears to be working as expected for me.

What are the steps to reproduce the issue using the test case?

PriceRightHTML5team
Aug 07, 2013, 4:20 AM
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

Daniil
Aug 07, 2013, 4:34 AM
So, there are three DateFields in the filter: Before, After and On. You are picking up a date in the On, right?

PriceRightHTML5team
Aug 07, 2013, 4:43 AM
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

Daniil
Aug 08, 2013, 6:25 AM
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;
}