May 13, 2010, 9:05 AM
Grid (Store) filtering question
Hi guys,
First of all sorry for my English here.
I would need some help to fix the following task:
- There is a store + grid (with 4 string column)
- Also there is a textbox, where the user enters the search keywords.
How can I search for a given keyword in all four string column ?
I tried to do that with Store.Filter("Columname", txtFilter.Text.Trim(), true, false); it is ok, but in this way I only can search in one column.
Here is the markup:
First of all sorry for my English here.
I would need some help to fix the following task:
- There is a store + grid (with 4 string column)
- Also there is a textbox, where the user enters the search keywords.
How can I search for a given keyword in all four string column ?
I tried to do that with Store.Filter("Columname", txtFilter.Text.Trim(), true, false); it is ok, but in this way I only can search in one column.
Here is the markup:
<!-- Begin Define Coolite Store for the Assets grid -->
<ext:Store ID="StoreAM" runat="server" DataSourceID="SqlDataSourceAM" AutoLoad="True"
IDMode="Legacy" IgnoreExtraFields="false" SerializationMode="Simple">
<Reader>
<ext:JsonReader ReaderID="AS_ID">
<Fields>
<ext:RecordField Name="AS_Asset_ID" />
<ext:RecordField Name="AS_Name" />
<ext:RecordField Name="AS_LicencePlate" />
<ext:RecordField Name="C_Name" />
<ext:RecordField Name="AS_Relation" />
<ext:RecordField Name="OwnerCompanyId" />
</Fields>
</ext:JsonReader>
</Reader>
<SortInfo Field="AS_Name" Direction="ASC" />
</ext:Store>
<!-- End -->
<!-- Begin Define grid for the Assets -->
<ext:GridPanel ID="GridPanelAM" runat="server" StoreID="StoreAM" Width="600px" Height="450px"
IDMode="Legacy" SelectionSavingBuffer="10" Border="False" AutoExpandColumn="AS_Name">
<TopBar runat="server">
<ext:Toolbar ID="tlbCommands" runat="server">
<Items>
<ext:Label runat="server" ID="lblIcon" Icon="PageWhiteFind">
</ext:Label>
<ext:TextField ID="txtFilter" runat="server" Text="[Enter asset filter]">
<AjaxEvents>
<SpecialKey Before="return e.getKey() == Ext.EventObject.ENTER;" Type="Submit" OnEvent="setFilter">
<EventMask ShowMask="true" Msg="Filtering..." MinDelay="300" />
</SpecialKey>
<Focus OnEvent="clearFilter">
</Focus>
<Blur OnEvent="resetFilter">
</Blur>
</AjaxEvents>
</ext:TextField>
</Items>
</ext:Toolbar>
</TopBar>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column DataIndex="AS_Asset_ID" Header="Asset ID" Width="100">
</PrepareCommand>
</PrepareCommands>
</ext:Column>
<ext:Column DataIndex="C_Name" Header="Company Name" Width="200">
</PrepareCommand>
</PrepareCommands>
</ext:Column>
<ext:Column DataIndex="AS_Name" Header="Asset Name">
</PrepareCommand>
</PrepareCommands>
</ext:Column>
<ext:Column DataIndex="AS_LicencePlate" Header="Licence Plate" Width="80">
</PrepareCommand>
</PrepareCommands>
</ext:Column>
<ext:CommandColumn Width="40">
<Commands>
<ext:GridCommand Icon="NoteEdit" CommandName="btnEdit_Click">
<ToolTip Text="Edit asset details" />
</ext:GridCommand>
</Commands>
</PrepareToolbar>
</PrepareGroupToolbar>
</ext:CommandColumn>
</Columns>
</ColumnModel>
<Plugins>
<ext:GridFilters ID="fltrGrid" runat="server" Local="true">
<Filters>
<ext:StringFilter DataIndex="AS_Asset_ID" />
<ext:StringFilter DataIndex="AS_Name" />
<ext:StringFilter DataIndex="C_Name" />
<ext:StringFilter DataIndex="AS_LicencePlate" />
</Filters>
</ext:GridFilters>
</Plugins>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
</SelectionModel>
<BottomBar>
<ext:PagingToolbar ID="PagingToolBar1" runat="server" StoreID="StoreAM" PageSize="16"
DisplayInfo="true" meta:resourcekey="PagingToolBar1Resource1" />
</BottomBar>
<AjaxEvents>
<Command OnEvent="gridbtnclick" Failure="Ext.MessageBox.alert('Select failed', 'Error during ajax event!');">
<ExtraParams>
<ext:Parameter Name="btn" Value="command" Mode="Raw" />
<ext:Parameter Name="id" Value="record.data.AS_Asset_ID" Mode="Raw" />
<ext:Parameter Name="name" Value="record.data.AS_Name" Mode="Raw" />
<ext:Parameter Name="licence" Value="record.data.AS_LicencePlate" Mode="Raw" />
<ext:Parameter Name="relation" Value="record.data.AS_Relation" Mode="Raw" />
<ext:Parameter Name="OwnerCompanyId" Value="record.data.OwnerCompanyId" Mode="Raw" />
<ext:Parameter Name="C_Name" Value="record.data.C_Name" Mode="Raw" />
</ExtraParams>
</Command>
</AjaxEvents>
</ext:GridPanel>
<!-- End grid -->
And here is the codebehind: [AjaxMethod]
protected void setFilter(object sender, AjaxEventArgs e)
{
string srctext = txtFilter.Text.Trim();
if (txtFilter.Text.Length > 0)
{
StoreAM.Filter("AS_Asset_ID", txtFilter.Text.Trim(), true, false);
StoreAM.Filter("AS_Name", txtFilter.Text.Trim(), true, false);
StoreAM.Filter("C_Name", txtFilter.Text.Trim(), true, false);
StoreAM.Filter("AS_LicencePlate", txtFilter.Text.Trim(), true, false);
}
else
{
StoreAM.ClearFilter();
}
}
[AjaxMethod]
public void clearFilter(object sender, AjaxEventArgs e)
{
txtFilter.Text = "";
}
[AjaxMethod]
public void resetFilter(object sender, AjaxEventArgs e)
{
if (txtFilter.Text.Trim() == "")
{
txtFilter.Text = "[Enter asset filter]";
StoreAM.ClearFilter();
}
}
Thanks for the help in advance, and please forgive me for the stupid question, I just getting know with the Coolite+ExtJS+C# :)