This is a migrated thread and some comments may be shown as answers.

Unable to create Google like Filtering

2 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Balamurali Venkatesan
Top achievements
Rank 1
Balamurali Venkatesan asked on 08 Oct 2008, 10:21 PM
HI,

Iam trying to create a Google like filtering in RadGrid.I used the sample specified by telerik in the following link
http://www.telerik.com/help/aspnet/grid/grdgooglelikefiltering.html

I used the the same class provided in the sample MyCustomFilteringColumn

I just tried by setting the Google filtering only for one column

When i execute the code the combo box is displaying but when i choose a value then on page reload it throws the following error

Sys.WebForms.PageRequestManagerServerErrorException: Failed to load viewstate. The control tree into whcih viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding cintrols dynamically, the comtrols added during a post-back must match the type and position of the controls added during the initial request.

Please see sample code

ASPX
------

<

telerik:RadGrid ID="radGridMarkets" runat="server" AllowPaging="True" AutoGenerateColumns="False"

 

GridLines="None" OnNeedDataSource="radGridMarkets_NeedDataSource" PageSize="100"

 

Skin="Office2007">

 

<AlternatingItemStyle BackColor="#EDEFF1" BorderColor="Blue" />

 

<ItemStyle BorderStyle="Solid" />

 

<PagerStyle AlwaysVisible="True" Mode="Advanced" Position="TopAndBottom" />

 

<ClientSettings>

 

<Selecting AllowRowSelect="true" />

 

</ClientSettings>

 

<MasterTableView AllowFilteringByColumn="true">

 

<RowIndicatorColumn>

 

<HeaderStyle Width="20px" />

 

</RowIndicatorColumn>

 

<ExpandCollapseColumn>

 

<HeaderStyle Width="20px" />

 

</ExpandCollapseColumn>

 

<Columns>

 

<telerik:GridBoundColumn DataField="Tag" HeaderText="Tag" UniqueName="_colTag">

 

</telerik:GridBoundColumn>

 

<telerik:GridBoundColumn

DataField="ShortDescription" HeaderText="Short Description"

 

UniqueName="_colMktShortDesc">

 

</telerik:GridBoundColumn>

 

<telerik:GridBoundColumn

DataField="LongDescription" HeaderText="Long Description"

 

UniqueName="_colMktLongDesc">

 

</telerik:GridBoundColumn>

 

<telerik:GridBoundColumn DataField="ExchngRateMarketTag" HeaderText="Exchange Rate Tag "

 

UniqueName="_colExchngRateMarketTag ">

 

</telerik:GridBoundColumn>

 

<telerik:GridBoundColumn DataField="ConvertLocalCurrency"

 

HeaderText="Convert Local Currency " UniqueName="_colMktConvertLocalCurrency ">

 

</telerik:GridBoundColumn>

 

<telerik:GridBoundColumn DataField="IndexConsolidation" HeaderText="Index Consolidation"

 

UniqueName="_colIndexConsolidation ">

 

</telerik:GridBoundColumn>

 

<telerik:GridBoundColumn DataField="MarketConsolidation" HeaderText="Market Consolidation"

 

UniqueName="_colMarketConsolidation">

 

</telerik:GridBoundColumn>

 

</Columns>

 

</MasterTableView>

 

<FilterMenu EnableTheming="True">

 

<CollapseAnimation Duration="200" Type="OutQuint" />

 

</FilterMenu>

 

<EditItemStyle BorderStyle="Solid" />

 

</telerik:RadGrid></telerik:RadPageView

 

MyCustomFilteringColumn Class File
----------------------------------------

#region

Google Filter template Column

 

 

public class MyCustomFilteringColumn : GridBoundColumn

 

{

 

private object listDataSource = null;

 

 

//RadGrid calls this method when it initializes the controls inside the filtering item cells

 

 

protected override void SetupFilterControls(TableCell cell)

 

{

 

base.SetupFilterControls(cell);

 

cell.Controls.RemoveAt(0);

 

RadComboBox list = new RadComboBox();

 

list.ID =

"list" + this.DataField;

 

list.AutoPostBack =

true;

 

list.EnableLoadOnDemand =

true;

 

list.MarkFirstMatch =

true;

 

list.ShowToggleImage =

false;

 

list.SelectedIndexChanged +=

new RadComboBoxSelectedIndexChangedEventHandler(list_SelectedIndexChanged);

 

cell.Controls.AddAt(0, list);

cell.Controls.RemoveAt(1);

list.Width = 100;

list.DataTextField =

this.DataField;

 

list.DataValueField =

this.DataField;

 

list.DataSource =

this.ListDataSource;

 

list.DataBind();

}

 

protected void list_SelectedIndexChanged(object sender, EventArgs e)

 

{

 

GridFilteringItem filterItem = (sender as DropDownList).NamingContainer as GridFilteringItem;

 

 

if (this.DataType == System.Type.GetType("System.Int32") ||

 

 

this.DataType == System.Type.GetType("System.Int16") ||

 

 

this.DataType == System.Type.GetType("System.Int64"))

 

{

filterItem.FireCommandEvent(

"Filter", new Pair("EqualTo", this.UniqueName));

 

}

 

else // treat everything else like a string

 

filterItem.FireCommandEvent(

"Filter", new Pair("Contains", this.UniqueName));

 

}

 

public object ListDataSource

 

{

 

get { return this.listDataSource; }

 

 

set { listDataSource = value; }

 

}

 

//RadGrid calls this method when the value should be set to the filtering input control(s)

 

 

protected override void SetCurrentFilterValueToControl(TableCell cell)

 

{

 

base.SetCurrentFilterValueToControl(cell);

 

 

RadComboBox list = (RadComboBox)cell.Controls[0];

 

 

if (this.CurrentFilterValue != string.Empty)

 

{

list.SelectedValue =

this.CurrentFilterValue;

 

}

}

 

//RadGrid calls this method to extract the filtering value from the filtering input control(s)

 

 

protected override string GetCurrentFilterValueFromControl(TableCell cell)

 

{

 

RadComboBox list = (RadComboBox)cell.Controls[0];

 

 

return list.SelectedValue;

 

}

 

protected override string GetFilterDataField()

 

{

 

return this.DataField;

 

}

}

#endregion

Code Behind:
----------------

//Add Google Filtering for Market Columns

radGridMarkets.MasterTableView.Columns.Clear();

 

GridBoundColumn col2 = new MyCustomFilteringColumn();

 

radGridMarkets.Columns.Add(col2);

col2.DataField =

"Tag";

 

col2.UniqueName = radGridMarkets.MasterTableView.Name +

"_colMktTag";

 

col2.HeaderText =

"Tag";

 

 

GridBoundColumn col3 = new GridBoundColumn();

 

radGridMarkets.Columns.Add(col3);

col3.DataField =

"ShortDescription";

 

col3.UniqueName = radGridMarkets.MasterTableView.Name +

"_colMktShortDescription";

 

col3.HeaderText =

"Short Description";

 

 

GridBoundColumn col4 = new GridBoundColumn();

 

radGridMarkets.Columns.Add(col4);

col4.DataField =

"LongDescription";

 

col4.UniqueName = radGridMarkets.MasterTableView.Name +

"_colMktLongDescription";

 

col4.HeaderText =

"Long Description";

 

 

GridBoundColumn col5 = new GridBoundColumn();

 

radGridMarkets.Columns.Add(col5);

col5.DataField =

"ExchngRateMarketTag";

 

col5.UniqueName = radGridMarkets.MasterTableView.Name +

"_colMktExchngRateMarketTag";

 

col5.HeaderText =

"Exchange Rate Tag";

 

 

GridBoundColumn col6 = new GridBoundColumn();

 

radGridMarkets.Columns.Add(col6);

col6.DataField =

"ConvertLocalCurrency";

 

col6.UniqueName = radGridMarkets.MasterTableView.Name +

"_colMktConvertLocalCurrency";

 

col6.HeaderText =

"Convert Local Currency";

 

 

GridBoundColumn col7 = new GridBoundColumn();

 

radGridMarkets.Columns.Add(col7);

col7.DataField =

"IndexConsolidation";

 

col7.UniqueName = radGridMarkets.MasterTableView.Name +

"_colMktIndexConsildation";

 

col7.HeaderText =

"Index Consolidation";

 

 

GridBoundColumn col8 = new GridBoundColumn();

 

radGridMarkets.Columns.Add(col8);

col8.DataField =

"MarketConsolidation";

 

col8.UniqueName = radGridMarkets.MasterTableView.Name +

"_colMktMarketConsolidation";

 

col8.HeaderText =

"Market Consolidation";

 




#region

RadMarkets Data Binding

 

 

protected void radGridMarkets_NeedDataSource(object source, GridNeedDataSourceEventArgs e)

 

{

 

 

if (!e.IsFromDetailTable)

 

{

 

int dbId = (int)HttpContext.Current.Session["INSTR_ID"];

 

 

List<InstrMarket> _lstmarket = _presenter.PopulateMarketsData(dbId);

 

 

foreach (GridBoundColumn column in radGridMarkets.MasterTableView.Columns)

 

{

 

if (column is MyCustomFilteringColumn)

 

{

 

List<String> itemsList = new List<String>();

 

 

foreach (InstrMarket item in _lstmarket)

 

{

itemsList.Add(item.Tag);

}

(column

as MyCustomFilteringColumn).ListDataSource = _lstmarket;

 

 

}

}

radGridMarkets.DataSource = _lstmarket;

}

}

 

private void radGridMarkets_ColumnCreating(object sender, GridColumnCreatingEventArgs e)

 

{

 

if ((e.ColumnType == typeof(MyCustomFilteringColumn).Name))

 

{

e.Column =

new MyCustomFilteringColumn();

 

}

}

 

protected void radGridMarkets_ItemCommand(object source, GridCommandEventArgs e)

 

{

 

if ((e.CommandName == "Filter"))

 

{

 

foreach (GridColumn column in e.Item.OwnerTableView.Columns)

 

{

column.CurrentFilterValue =

string.Empty;

 

column.CurrentFilterFunction =

GridKnownFunction.NoFilter;

 

}

}

}

#endregion





2 Answers, 1 is accepted

Sort by
0
Balamurali Venkatesan
Top achievements
Rank 1
answered on 09 Oct 2008, 01:59 PM
Any Update on this would be a great help.

Also I now chnaged the Datasource setting to the Items_requested Event as shown below.

But now no data is being loaded to the RADCOMBO

private

void list_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)

 

{

(o

as RadComboBox).DataTextField = this.DataField;

 

(o

as RadComboBox).DataValueField = this.DataField;

 

(o

as RadComboBox).DataSource =GetDataTable("SELECT DISTINCT " + this.UniqueName + " as TAG FROM GS_CLT_DB_MARKETS ");

 

 

//"WHERE " + this.UniqueName + " LIKE '" + e.Text + "%'");

 

(o

as RadComboBox).DataBind();

 

}




protected

override void SetupFilterControls(TableCell cell)

 

{

 

base.SetupFilterControls(cell);

 

cell.Controls.RemoveAt(0);

 

RadComboBox combo = new RadComboBox();

 

combo.ID = (

"RadComboBox1" + this.DataField);

 

combo.ShowToggleImage =

false;

 

combo.Skin =

"Office2007";

 

combo.EnableLoadOnDemand =

true;

 

combo.AutoPostBack =

true;

 

combo.MarkFirstMatch =

true;

 

combo.Height =

Unit.Pixel(100);

 

combo.DataTextField =

this.DataField;

 

combo.ItemsRequested +=

new RadComboBoxItemsRequestedEventHandler(list_ItemsRequested);

 

combo.SelectedIndexChanged +=

new RadComboBoxSelectedIndexChangedEventHandler(list_SelectedIndexChanged);

 

cell.Controls.AddAt(0, combo);

cell.Controls.RemoveAt(1);

}

0
Iana Tsolova
Telerik team
answered on 14 Oct 2008, 07:38 AM
Hello Balamurali,

I suggest that you look at this topic and check if you have followed the steps pointed there in order to achieve the Google-like filtering. The above article is specified for RadGrid for ASP.NET AJAX where as the help topic you look from is for RadGrid for ASP.NET.

Let me know how it goes.

Kind regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Balamurali Venkatesan
Top achievements
Rank 1
Answers by
Balamurali Venkatesan
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or