or
Hi.!
I have a Rad Grid control in my ASPX page, then I bind this control (server side binding) to a data table that I get from a web service. I want to implement a client side filtering, but I don’t know how to do this or what things I need to change in order to do that. I think this is possible, because all the information I got, is now in client side (My table with all the rows.!! )
I successfully implement server side filtering but this is very slow, so sadly this is not an option for me. :(
Here’s a sample of my code (server side filtering):
ASPX:
<telerik:RadGrid ID="gdOrders" AllowFilteringByColumn="True" runat="server" OnItemCommand="onItemCmd"> <MasterTableView AllowFilteringByColumn="True"> <Columns> <telerik:GridBoundColumn DataField="CSOL_FOLIOOTID" ShowFilterIcon="false" HeaderText="Folio" UniqueName="CSOL_FOLIOOTID" Resizable="False" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" AllowFiltering="true" /> . . . </Columns> </MasterTableView></telerik:RadGrid>
CODE BEHIND
myDataTable = myObjInstance.GetOrders();gdOrders.DataSource = myDataTable;gdOrders.DataBind();protected void onItemCmd(object source, Telerik.Web.UI.GridCommandEventArgs e) { switch (e.CommandName) { case RadGrid.FilterCommandName: Pair filterPair = (Pair)e.CommandArgument; TextBox filterBox = (e.Item as GridFilteringItem) [filterPair.Second.ToString()].Controls[0] as TextBox; this.ApplyFilter((string)filterPair.Second, filterBox.Text); break; } } } private void ApplyFilter(string clmnName, string value) { string query = clmnName + " like '%" + value.Trim() + "%'"; gdOrders.DataSource = myDataTable.Select(query); gdOrders.DataBind(); }
Can any one suggest me how to do this, what should I change or implement?
Tnks :D
Sorry for my English!!
<%@ Page Title="" Language="C#" MasterPageFile="~/OverShort/OverShort.Master" AutoEventWireup="true" CodeBehind="BillsOfLading.aspx.cs" Inherits="ODSWebSite.OverShort.BillOfLadings" %><%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %><asp:Content ID="Content1" ContentPlaceHolderID="cphOSHead" runat="server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="cphOSMain" runat="server"> <!-- NOTE: For export to work... --> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> <ClientEvents OnRequestStart="onRequestStart" /> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="ButtonSearch"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="pnlAll" LoadingPanelID="AjaxLoadingPanel1" /> <telerik:AjaxUpdatedControl ControlID="ButtonSearch" /> <telerik:AjaxUpdatedControl ControlID="RadGridBOLDetail"/> <telerik:AjaxUpdatedControl ControlID="RadGridBOLSummary"/> <telerik:AjaxUpdatedControl ControlID="lblError" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="RadGridBOLDetail"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="pnlAll" LoadingPanelID="AjaxLoadingPanel1" /> <telerik:AjaxUpdatedControl ControlID="RadGridBOLDetail" /> <telerik:AjaxUpdatedControl ControlID="lblError" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="RadGridBOLSummary"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="pnlAll" LoadingPanelID="AjaxLoadingPanel1" /> <telerik:AjaxUpdatedControl ControlID="RadGridBOLSummary" /> <telerik:AjaxUpdatedControl ControlID="lblError" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="RadDateTimePickerFrom"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadDateTimePickerFrom" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="RadDateTimePickerTo"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadDateTimePickerTo" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="RadComboBoxTASLocations"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadComboBoxTASLocations" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadAjaxLoadingPanel runat="server" ID="AjaxLoadingPanel1" MinDisplayTime="50"></telerik:RadAjaxLoadingPanel> <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="CheckBoxes, Buttons, Scrollbars, Textarea, Fieldset, Label, Zone, GridFormDetailsViews" /> <asp:Panel ID="pnlAll" runat="server"> <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" > <asp:Label ID="lblError" runat="server"></asp:Label> <table> <tr> <td class="tdLabel"><label id="lblLocation" runat="server">Location:</label></td> <td> <telerik:RadComboBox ID="RadComboBoxTASLocations" runat="server" DataSourceID="LocationsDataSource" DataTextField="TypeDisplayValue" DataValueField="TypeValue" AutoPostBack="false" CausesValidation="False" Height="200" width="200" DropDownWidth="250" > </telerik:RadComboBox> </td> <td class="tdLabel"><label id="lblFrom" runat="server">From:</label></td> <td><telerik:RadDateTimePicker ID="RadDateTimePickerFrom" Runat="server" Width="180" MinDate="2010-01-01"> <Calendar runat="server" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x" ShowRowHeaders="false"></Calendar> <TimeView ID="TimeView1" runat="server" CellSpacing="-1" Culture="English (United Kingdom)" EndTime="23:59:00" RenderDirection="Vertical" Columns="2"></TimeView> <TimePopupButton HoverImageUrl="" ImageUrl="" /> <DatePopupButton HoverImageUrl="" ImageUrl="" /> <DateInput ID="DateInput1" runat="server" DateFormat="M/d/yyyy HH:mm" DisplayDateFormat="M/d/yyyy HH:mm"> </DateInput> </telerik:RadDateTimePicker> </td> <td class="tdLabel"><label id="lblTo" runat="server">To:</label></td> <td><telerik:RadDateTimePicker ID="RadDateTimePickerTo" Runat="server" Width="180" MinDate="2010-01-01"> <Calendar runat="server" UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x" ShowRowHeaders="false"></Calendar> <TimeView ID="TimeView2" runat="server" CellSpacing="-1" Culture="English (United Kingdom)" EndTime="23:59:00" RenderDirection="Vertical" Columns="2"></TimeView> <TimePopupButton HoverImageUrl="" ImageUrl="" /> <DatePopupButton HoverImageUrl="" ImageUrl="" /> <DateInput ID="DateInput2" runat="server" DateFormat="M/d/yyyy HH:mm" DisplayDateFormat="M/d/yyyy HH:mm"> </DateInput> </telerik:RadDateTimePicker> </td> <td><asp:Button ID="ButtonSearch" runat="server" Text="Search" onclick="ButtonSearch_Click" /></td> </tr> </table> <telerik:RadPanelBar ID="rpbBOLSummary" runat="server" Width="100%" > <Items> <telerik:RadPanelItem runat="server" Expanded="True" Text="Summary"> <Items> <telerik:RadPanelItem runat="server" Value="BOLSummary"> <ItemTemplate> <telerik:RadGrid ID="RadGridBOLSummary" runat="server" Visible="false" AllowFilteringByColumn="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="myBillOfLadingsSummaryODS" GridLines="Vertical" onsortcommand="RadGridBOLSummary_SortCommand" onitemdatabound="RadGridBOLSummary_ItemDataBound" OnItemCommand="RadGridBOLSummary_ItemCommand" ShowFooter="True" ShowStatusBar="True" Width="650px" GroupingEnabled="False" > <GroupingSettings CaseSensitive="false" /> <MasterTableView DataSourceID="myBillOfLadingsSummaryODS" CommandItemDisplay="Top" GridLines="Vertical" AllowPaging="true" PageSize="20"> <PagerStyle Mode="NextPrevNumericAndAdvanced" Position="TopAndBottom" /> <commanditemsettings showexporttoexcelbutton="True" showexporttopdfbutton="false" ShowAddNewRecordButton="false"/> <Columns> <telerik:GridBoundColumn DataField="InventoryDate" HeaderText="Inventory Date" SortExpression="InventoryDate" UniqueName="InventoryDate" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy HH:mm}"> <ItemStyle Wrap="false" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ProductID" HeaderText="Product ID" SortExpression="ProductID" UniqueName="ProductID" DataType="System.String" FilterControlWidth="50px"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="BillIDCountATLAS" HeaderText="Bill Count (ATLAS)" SortExpression="BillIDCountATLAS" UniqueName="BillIDCountATLAS" DataType="System.Int32" DataFormatString="{0:#,###0}" FilterControlWidth="60px"> <ItemStyle HorizontalAlign="Right" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="BillVolumeSumATLAS" HeaderText="Bill Vol (ATLAS)" SortExpression="BillVolumeSumATLAS" UniqueName="BillVolumeSumATLAS" DataType="System.Int32" DataFormatString="{0:#,###0}" FilterControlWidth="60px"> <ItemStyle HorizontalAlign="Right" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="BillIDCountTAS" HeaderText="Bill Count (TAS)" SortExpression="BillIDCountTAS" UniqueName="BillIDCountTAS" DataType="System.Int32" DataFormatString="{0:#,###0}" FilterControlWidth="60px"> <ItemStyle HorizontalAlign="Right" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="BillVolumeSumTAS" HeaderText="Bill Vol (TAS)" SortExpression="BillVolumeSumTAS" UniqueName="BillVolumeSumTAS" DataType="System.Int32" DataFormatString="{0:#,###0}" FilterControlWidth="60px"> <ItemStyle HorizontalAlign="Right" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="BillVolumeSumTASBBL" HeaderText="Bill Vol (TAS) BBL" SortExpression="BillVolumeSumTASBBL" UniqueName="BillVolumeSumTASBBL" DataType="System.Int32" DataFormatString="{0:#,###0}" FilterControlWidth="60px"> <ItemStyle HorizontalAlign="Right" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="VolumeVariance" HeaderText="Vol Variance" SortExpression="VolumeVariance" UniqueName="VolumeVariance" DataType="System.Int32" DataFormatString="{0:#,###0}" FilterControlWidth="60px"> <ItemStyle HorizontalAlign="Right" /> </telerik:GridBoundColumn> </Columns> <EditFormSettings> <EditColumn UniqueName="EditCommandColumn1"> </EditColumn> </EditFormSettings> </MasterTableView> <ClientSettings AllowDragToGroup="False"></ClientSettings> </telerik:RadGrid> </ItemTemplate> </telerik:RadPanelItem> </Items> </telerik:RadPanelItem> </Items> </telerik:RadPanelBar> <br /> <telerik:RadPanelBar ID="rpBOLDetail" runat="server" Width="100%" > <Items> <telerik:RadPanelItem runat="server" Expanded="True" Text="Detail"> <Items> <telerik:RadPanelItem runat="server" Value="BOLDetail"> <ItemTemplate> <telerik:RadGrid ID="RadGridBOLDetail" runat="server" Visible="false" AllowFilteringByColumn="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="myBillOfLadingsDetailODS" GridLines="Vertical" onsortcommand="RadGridBOLDetail_SortCommand" OnItemCommand="RadGridBOLDetail_ItemCommand" ShowFooter="True" ShowStatusBar="True" Width="650px" GroupingEnabled="true" > <GroupingSettings CaseSensitive="false" /> <MasterTableView DataSourceID="myBillOfLadingsDetailODS" CommandItemDisplay="Top" GridLines="Vertical" AllowPaging="true" PageSize="20"> <PagerStyle Mode="NextPrevNumericAndAdvanced" Position="TopAndBottom" /> <GroupByExpressions> <telerik:GridGroupByExpression> <GroupByFields> <telerik:GridGroupByField FieldName="ProductID" /> </GroupByFields> <SelectFields> <telerik:GridGroupByField FieldName="ProductID" HeaderText="Product ID" /> </SelectFields> </telerik:GridGroupByExpression> </GroupByExpressions> <commanditemsettings showexporttoexcelbutton="True" showexporttopdfbutton="false" ShowAddNewRecordButton="false"/> <Columns> <telerik:GridBoundColumn DataField="InventoryDate" HeaderText="Inventory Date" SortExpression="InventoryDate" UniqueName="InventoryDate" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy HH:mm}"> <ItemStyle Wrap="false" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="BillID" HeaderText="Bill ID" SortExpression="BillID" UniqueName="BillID" DataType="System.String"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="DetailType" HeaderText="Detail Type" SortExpression="DetailType" UniqueName="DetailType" FilterControlWidth="50px"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ProductID" HeaderText="Product ID" SortExpression="ProductID" UniqueName="ProductID" FilterControlWidth="50px"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="NetVolume" HeaderText="Net Volume" SortExpression="NetVolume" UniqueName="NetVolume" DataType="System.Int32" DataFormatString="{0:#,###0}" FilterControlWidth="70px"> <ItemStyle HorizontalAlign="Right" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="UOM" HeaderText="UOM" SortExpression="UOM" UniqueName="UOM" FilterControlWidth="50px"> <ItemStyle HorizontalAlign="Center" /> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ATLASProcessStatus" HeaderText="ATLASProcessStatus" SortExpression="ATLASProcessStatus" UniqueName="ATLASProcessStatus"> </telerik:GridBoundColumn> </Columns> <EditFormSettings> <EditColumn UniqueName="EditCommandColumn1"> </EditColumn> </EditFormSettings> </MasterTableView> <ClientSettings AllowDragToGroup="False"> </ClientSettings> </telerik:RadGrid> </ItemTemplate> </telerik:RadPanelItem> </Items> </telerik:RadPanelItem> </Items> </telerik:RadPanelBar> </telerik:RadAjaxPanel> </asp:Panel> <br /><asp:ObjectDataSource ID="LocationsDataSource" runat="server" DataObjectTypeName="Enterprise.ODS.DataObjects.Assets.StringCriteriaType" TypeName="Enterprise.ODS.BLL.Shared.LocationsODS" SelectMethod="GetUserLocationsWithKeyAndDescription" onselecting="LocationsDataSource_Selecting" > <SelectParameters> <asp:Parameter Name="user" /> </SelectParameters></asp:ObjectDataSource><asp:ObjectDataSource ID="myBillOfLadingsDetailODS" runat="server" CacheDuration="120" DataObjectTypeName="Enterprise.ODS.DataObjects.OverShort.BOLDetail" TypeName="Enterprise.ODS.BLL.OverShort.BOLDetailsODS" SelectMethod="BillOfLadingDetails" OnUpdated="ObjDataSource_Event" EnableCaching="False" onselected="ObjDataSource_Selected" onselecting="ObjDataSource_Selecting"> <SelectParameters> <asp:ControlParameter Name="locationKey" ControlID="RadComboBoxTASLocations" Type="Int32" Direction="Input"/> <asp:ControlParameter Name="dateFrom" ControlID="RadDateTimePickerFrom" Type="DateTime" Direction="Input" /> <asp:ControlParameter Name="dateTo" ControlID="RadDateTimePickerTo" Type="DateTime" Direction="Input" /> <asp:Parameter DefaultValue="" Name="sortExpression" Type="String" /> <asp:Parameter DefaultValue="" Name="sortDirection" Type="String" /> </SelectParameters></asp:ObjectDataSource><asp:ObjectDataSource ID="myBillOfLadingsSummaryODS" runat="server" CacheDuration="120" DataObjectTypeName="Enterprise.ODS.DataObjects.OverShort.RackToAtlasComparison" TypeName="Enterprise.ODS.BLL.OverShort.RackToAtlasComparisonODS" SelectMethod="BillOfLadingSummary" OnUpdated="ObjDataSource_Event" EnableCaching="False" onselected="ObjDataSource_Selected" onselecting="ObjDataSource_Selecting"> <SelectParameters> <asp:ControlParameter Name="locationKey" ControlID="RadComboBoxTASLocations" Type="Int32" Direction="Input"/> <asp:ControlParameter Name="dateFrom" ControlID="RadDateTimePickerFrom" Type="DateTime" Direction="Input" /> <asp:ControlParameter Name="dateTo" ControlID="RadDateTimePickerTo" Type="DateTime" Direction="Input" /> <asp:Parameter DefaultValue="" Name="sortExpression" Type="String" /> <asp:Parameter DefaultValue="" Name="sortDirection" Type="String" /> </SelectParameters></asp:ObjectDataSource> </asp:Content><asp:Content ID="Content3" ContentPlaceHolderID="cphOSSideTasks" runat="server"></asp:Content>using System;using System.Globalization;using System.Web.UI.WebControls;using Telerik.Web.UI;using Enterprise.ODS.DataObjects;using Enterprise.Utilities.DataAccessCore;using Enterprise.ODS.DAL.OverShort;namespace ODSWebSite.OverShort{ public partial class BillOfLadings : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Shared.Helpers.FormatErrorLabel(ref lblError, true, "");// reset error label on page load if (!Page.IsPostBack) { // Select the page in the local nav bar ((OverShort)(Page.Master)).SelectPage(OverShort.OverShortPages.BillsOfLading); ODSWebSite.Shared.Helpers.SetDefaultLocationAndDateRange(User.Identity.Name, ref RadComboBoxTASLocations, ref RadDateTimePickerFrom, ref RadDateTimePickerTo); } } #region grid events protected void RadGridBOLSummary_SortCommand(object source, GridSortCommandEventArgs e) { Shared.Helpers.SetSortOrderForObjDataSource(myBillOfLadingsSummaryODS, e); } protected void RadGridBOLDetail_SortCommand(object source, GridSortCommandEventArgs e) { Shared.Helpers.SetSortOrderForObjDataSource(myBillOfLadingsDetailODS, e); } protected void RadGridBOLSummary_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem ) { GridDataItem dataBoundItem = e.Item as GridDataItem; int volVariance ; if (int.TryParse(dataBoundItem["VolumeVariance"].Text, NumberStyles.Integer | NumberStyles.AllowThousands,CultureInfo.InvariantCulture, out volVariance)) { if (volVariance != 0) { dataBoundItem["VolumeVariance"].ForeColor = System.Drawing.Color.Red; dataBoundItem["VolumeVariance"].Font.Bold = true; } } } } protected void RadGridBOLDetail_ItemCommand(object source, GridCommandEventArgs e) { RadGrid grid = ((RadGrid)Shared.Helpers.FindControlRecursive(rpBOLDetail, "RadGridBOLDetail")); Shared.Helpers.RadGridItemCommandForExport(ref grid, e); } protected void RadGridBOLSummary_ItemCommand(object source, GridCommandEventArgs e) { RadGrid grid = ((RadGrid)Shared.Helpers.FindControlRecursive(rpbBOLSummary, "RadGridBOLSummary")); Shared.Helpers.RadGridItemCommandForExport(ref grid, e); } #endregion #region object data source events protected void ObjDataSource_Selected(object sender, ObjectDataSourceStatusEventArgs e) { Shared.Helpers.ObjDataSource_Selected(ref lblError, e); } protected void ObjDataSource_Event(object sender, ObjectDataSourceStatusEventArgs e) { Shared.Helpers.ObjDataSource_Event(ref lblError, sender, e); } protected void LocationsDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e) { e.InputParameters["user"] = Page.User.Identity.Name; } #endregion protected void ButtonSearch_Click(object sender, EventArgs e) { string errorMessage = ""; if (Shared.Helpers.LocationDateRangeIsOK( ref RadComboBoxTASLocations, ref RadDateTimePickerFrom, ref RadDateTimePickerTo, ref errorMessage)) { ((RadGrid)Shared.Helpers.FindControlRecursive(rpBOLDetail, "RadGridBOLDetail")).Rebind(); ((RadGrid)Shared.Helpers.FindControlRecursive(rpBOLDetail, "RadGridBOLDetail")).Visible = true; //myBillOfLadingsDetailODS.Select(); ((RadGrid)Shared.Helpers.FindControlRecursive(rpbBOLSummary, "RadGridBOLSummary")).Rebind(); ((RadGrid)Shared.Helpers.FindControlRecursive(rpbBOLSummary, "RadGridBOLSummary")).Visible = true; //myBillOfLadingsSummaryODS.Select(); } else Shared.Helpers.FormatErrorLabel(ref lblError, false, errorMessage); } protected void ObjDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e) { // Stop data from loading on intial page load if (!Page.IsPostBack) { //don't auto-search when page loads e.Cancel = true; } else { string errorMessage = ""; if (!(Shared.Helpers.LocationDateRangeIsOK( ref RadComboBoxTASLocations, ref RadDateTimePickerFrom, ref RadDateTimePickerTo, ref errorMessage))) { Shared.Helpers.FormatErrorLabel(ref lblError, false, errorMessage); e.Cancel = true; } else { Shared.Helpers.FormatErrorLabel(ref lblError, true, ""); } } } }}