Jun 21, 2017, 2:09 PM
EXT 3.3 How to override string filter for searching using wildcards
Hello
I need to customize a string filter on a grid panel using Grid Plugins i.e GridFilters. When you search in a string filter it performs a contains in the string. I would like to be able to use some wildards i.e +ABC to return only rows that include an exact match for ABC. I have tried to override the string filter validateRecord but it is not being called.
Can you recommend some way to do that
thanks
I need to customize a string filter on a grid panel using Grid Plugins i.e GridFilters. When you search in a string filter it performs a contains in the string. I would like to be able to use some wildards i.e +ABC to return only rows that include an exact match for ABC. I have tried to override the string filter validateRecord but it is not being called.
Can you recommend some way to do that
thanks
<ext:GridPanel ID="GridPanel1" runat="server" Border="false">
<Store>
<ext:Store ID="Store1" runat="server" PageSize="10">
<Model>
<ext:Model runat="server" IDProperty="Id">
<Fields>
<ext:ModelField Name="Id" Type="Int" />
<ext:ModelField Name="Company" Type="String" />
<ext:ModelField Name="Price" Type="Float" />
<ext:ModelField Name="Date" Type="Date" />
<ext:ModelField Name="Size" Type="String" />
<ext:ModelField Name="Visible" Type="Boolean" />
</Fields>
</ext:Model>
</Model>
<Sorters>
<ext:DataSorter Property="Company" Direction="ASC" />
</Sorters>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="ID" DataIndex="Id">
<Filter>
<ext:NumberFilter />
</Filter>
</ext:Column>
<ext:Column ID="CompanyColumn" runat="server" Text="Company" DataIndex="Company" Flex="1">
<Filter>
<ext:StringFilter />
</Filter>
</ext:Column>
<ext:Column runat="server" Text="Size" DataIndex="Size">
<Filter>
<ext:ListFilter Options="extra small,small,medium,large,extra large" />
</Filter>
</ext:Column>
</Columns>
</ColumnModel>
<Plugins>
<ext:GridFilters runat="server" />
</Plugins>
</ext:GridPanel>
Ext.onReady(function () {
Ext.grid.filters.filter.String.override({
isActivatable: function () {
console.log('activate');
return Ext.isString(this.inputItem.getValue());
}
});
Ext.grid.filters.filter.String.override({
validateRecord: function (record) {
console.log('validateRecord');
var val = record.get(this.dataIndex);
if (typeof val != "string") {
return this.getValue().length == 0;
}
if (Ext.isEmpty(val, true)) {
val = "";
}
var strValue = this.getValue().toLowerCase();
return (val.toLowerCase().match("^" + strValue) == strValue);
}
});
});