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

Filtering and Dymanic Columns

3 Answers 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ali ayhan
Top achievements
Rank 1
ali ayhan asked on 01 Jul 2010, 05:59 PM
Hi
This code in the page load and I am not control page postback.
 
.......  
RadGrid1.Columns.Clear();  
RadGrid1.MasterTableView.Columns.Clear();  
RadGrid1.AutoGenerateColumns = false;  
 
GridBoundColumn boundColumn;  
for (int i = 0; i < dt.Columns.Count; i++)  
{  
if (Request.QueryString["calc"].ToString().Contains(dt.Columns[i].ColumnName.ToString()))  
{  
    boundColumn = new GridBoundColumn();  
    boundColumn.DataField = dt.Columns[i].ColumnName.ToString();  
    boundColumn.HeaderText = dt.Columns[i].ColumnName.ToString();  
    boundColumn.Groupable = true;  
    boundColumn.UniqueName = dt.Columns[i].ColumnName.ToString();  
 
    string[] sumColums = Request.QueryString["calc"].ToString().Split('-');  
 
    for (int a = 0; a < sumColums.Length; a++)  
    {  
        if (sumColums[a].Contains(dt.Columns[i].ColumnName.ToString()))  
        {  
            string[] colFormat = sumColums[a].Split(',');  
            boundColumn.FooterAggregateFormatString = colFormat[1].ToString();  
 
            if (colFormat[2].ToString() == "sum")  
            {  
                boundColumn.Aggregate = GridAggregateFunction.Sum;  
            }  
            else if (colFormat[2].ToString() == "count")  
            {  
                boundColumn.Aggregate = GridAggregateFunction.Count;  
            }  
            else if (colFormat[2].ToString() == "avg")  
            {  
                boundColumn.Aggregate = GridAggregateFunction.Avg;  
            }  
        }  
    }  
 
    RadGrid1.MasterTableView.Columns.Add(boundColumn);  
}  
 
.... 

So my problem is, when I filter a columns is ok, but when I filter other columns, my before filter values gone. I miss my before filter values. My question, how can I set again before filter columns values?

Hashtable hsFiltering = new Hashtable();  
for (int i = 0; i < RadGrid1.Columns.Count; i++)  
{  
    hsFiltering[RadGrid1.Columns[i].HeaderText] = RadGrid1.Columns[i].CurrentFilterValue;  
I get before filter values via this code, but I can not bind filter value again after postback.

Thank you.

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 02 Jul 2010, 04:49 PM
Hello Ali,

I suggest that you examine the online example below which demonstrates saving and restoring RadGrid settings by user:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/savinggridsettingsonperuserbasis/defaultcs.aspx

Give it a try and let me know if it helps.

Greetings,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
ali ayhan
Top achievements
Rank 1
answered on 02 Jul 2010, 07:14 PM
//Solution:


protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        if (Request.QueryString["calc"] != null)  
        {  
            string[] calcColums = Request.QueryString["calc"].ToString().Split('-');  
 
            for (int i = 0; i < calcColums.Length; i++)  
            {  
 
                string colName = calcColums[i].Split(',')[0];  
                string format = calcColums[i].Split(',')[1];  
                string agg = calcColums[i].Split(',')[2];  
 
                GridBoundColumn column2 = (GridBoundColumn)RadGrid1.MasterTableView.GetColumnSafe(colName);  
                try  
                {  
                    column2.FooterAggregateFormatString = format;  
                    column2.DataFormatString = format;  
                }  
                catch { }  
 
                switch (agg)  
                {  
                    case "sum":  
                        column2.Aggregate = GridAggregateFunction.Sum;  
                        break;  
                    case "count":  
                        column2.Aggregate = GridAggregateFunction.Count;  
                        break;  
                    case "avg":  
                        column2.Aggregate = GridAggregateFunction.Avg;  
                        break;  
                    default: break;  
                }  
 
            }  
 
            RadGrid1.Rebind();  
        }  
    } 

0
Pavlina
Telerik team
answered on 05 Jul 2010, 09:38 AM
Hi Ali,

I am glad to hear that you managed to solve the problem. In case you need further assistance or you have additional questions, do not hesitate to contact me again.

Kind regards,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
ali ayhan
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
ali ayhan
Top achievements
Rank 1
Share this question
or