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

Save Filter

7 Answers 310 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ldc0618
Top achievements
Rank 1
ldc0618 asked on 24 Apr 2008, 12:00 AM
I have a datagrid with the filtering headers turned on. It works great but I need to allow the user the save the filter definition so that the filter can be re-used by other users. Is this possible?

Thanks!

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Apr 2008, 07:42 AM
Hi,

Go through the following help document link.
Saving grid settings on a per user basis

Thanks
Shinu.
0
Ted
Top achievements
Rank 1
answered on 10 Jun 2008, 04:10 PM
I used this example and while it is working, the Filter Doesn't show up in the Filter Textbox but the Text of the filter is working.  so I have a column named "Last Name" and I filter the column to names that Contain the Letters "Fa".  this works fine and using the example above I store the string in a session variable.  then the users links to another page and then links back.  in init, I am loading the values again by this

if

(Session["RadGridSettings"] != null)

{

GridSettingsPersister gs = new GridSettingsPersister(RadGrid1);

gs.LoadSettings(Session[

"RadGridSettings"].ToString());

}
and the filter works but it doesn't put the "Fa" back in the FilterTextBox of the "Last Name" Column.  Is there a way to get this to show up?

0
Jeremy Wadsworth
Top achievements
Rank 1
answered on 22 Jun 2008, 03:37 AM
I noticed you haven't received an answer to this. I submitted a support ticket for this a while back. I implemented saving the filter for a client, but of course they are now wanting to know what filter is being applied.
0
Guss
Top achievements
Rank 2
answered on 30 Jun 2008, 10:41 AM
I have also implimented this solution, AND would also like to know how to put the "FA" back in the filtertextbox.
0
Ted
Top achievements
Rank 1
answered on 30 Jun 2008, 12:10 PM
Just to update with my solution, I modified the persister class to look like this and it seems to work for me. 

public

class GridSettingsPersister

{

private RadGrid gridInstance;

public GridSettingsPersister(RadGrid gridInstance)

{

this.gridInstance = gridInstance;

}

//this method should be called on Render

public string SaveSettings()

{

object[] gridSettings = new object[7];

//Save groupBy

GridGroupByExpressionCollection groupByExpressions = gridInstance.MasterTableView.GroupByExpressions;

object[] groupExpressions = new object[groupByExpressions.Count];

int count = 0;

foreach (GridGroupByExpression expression in groupByExpressions)

{

groupExpressions[count] = ((

IStateManager)expression).SaveViewState();

count++;

}

gridSettings[0] = groupExpressions;

//Save sort expressions

gridSettings[1] = ((

IStateManager)gridInstance.MasterTableView.SortExpressions).SaveViewState();

//Save columns order

int columnsLength = gridInstance.MasterTableView.Columns.Count +

gridInstance.MasterTableView.AutoGeneratedColumns.Length;

Pair[] columnOrder = new Pair[columnsLength];

ArrayList allColumns = new ArrayList(columnsLength);

allColumns.AddRange(gridInstance.MasterTableView.Columns);

allColumns.AddRange(gridInstance.MasterTableView.AutoGeneratedColumns);

int i = 0;

foreach (GridColumn column in allColumns)

{

Pair p = new Pair();

p.First = column.OrderIndex;

p.Second = column.HeaderStyle.Width;

columnOrder[i] = p;

i++;

}

gridSettings[2] = columnOrder;

//Save filter expression

gridSettings[3] = (

object)gridInstance.MasterTableView.FilterExpression;

//Save AllowFilteringByColumn setting

gridSettings[4] = (

object)gridInstance.MasterTableView.AllowFilteringByColumn;

//Save Filter Column Headings Text

Pair[] columnOrder2 = new Pair[columnsLength];

ArrayList allColumns2 = new ArrayList(columnsLength);

allColumns2.AddRange(gridInstance.MasterTableView.Columns);

allColumns2.AddRange(gridInstance.MasterTableView.AutoGeneratedColumns);

int r = 0;

foreach (GridColumn column in allColumns2)

{

Pair p = new Pair();

p.First = column.CurrentFilterFunction;

p.Second = column.CurrentFilterValue;

columnOrder2[r] = p;

r++;

}

gridSettings[5] = columnOrder2;

 

 

LosFormatter formatter = new LosFormatter();

StringWriter writer = new StringWriter();

formatter.Serialize(writer, gridSettings);

return writer.ToString();

}

//this method should be called on PageInit

public void LoadSettings(string settings)

{

LosFormatter formatter = new LosFormatter();

StringReader reader = new StringReader(settings);

object[] gridSettings = (object[])formatter.Deserialize(reader);

//Load groupBy

GridGroupByExpressionCollection groupByExpressions = this.gridInstance.MasterTableView.GroupByExpressions;

groupByExpressions.Clear();

object[] groupExpressionsState = (object[])gridSettings[0];

int count = 0;

foreach (object obj in groupExpressionsState)

{

GridGroupByExpression expression = new GridGroupByExpression();

((

IStateManager)expression).LoadViewState(obj);

groupByExpressions.Add(expression);

count++;

}

//Load sort expressions

this.gridInstance.MasterTableView.SortExpressions.Clear();

((

IStateManager)this.gridInstance.MasterTableView.SortExpressions).LoadViewState(gridSettings[1]);

//Load columns order

int columnsLength = this.gridInstance.MasterTableView.Columns.Count +

this.gridInstance.MasterTableView.AutoGeneratedColumns.Length;

Pair[] columnOrder = (Pair[])gridSettings[2];

if (columnsLength == columnOrder.Length)

{

ArrayList allColumns = new ArrayList(columnsLength);

allColumns.AddRange(

this.gridInstance.MasterTableView.Columns);

allColumns.AddRange(

this.gridInstance.MasterTableView.AutoGeneratedColumns);

int i = 0;

foreach (GridColumn column in allColumns)

{

column.OrderIndex = (

int)columnOrder[i].First;

column.HeaderStyle.Width = (

Unit)columnOrder[i].Second;

i++;

}

}

//Load AllowFilteringByColumn setting

this.gridInstance.MasterTableView.AllowFilteringByColumn = (bool)gridSettings[4];

//Load filter expression

this.gridInstance.MasterTableView.FilterExpression = (string)gridSettings[3];

//Load Filter columns text

Pair[] columnOrder2 = (Pair[])gridSettings[5];

if (columnsLength == columnOrder2.Length)

{

ArrayList allColumns = new ArrayList(columnsLength);

allColumns.AddRange(

this.gridInstance.MasterTableView.Columns);

allColumns.AddRange(

this.gridInstance.MasterTableView.AutoGeneratedColumns);

int i = 0;

foreach (GridColumn column in allColumns)

{

column.CurrentFilterFunction = (

GridKnownFunction)columnOrder2[i].First;

column.CurrentFilterValue = (

string)columnOrder2[i].Second;

i++;

}

}

}

}

0
Guss
Top achievements
Rank 2
answered on 30 Jun 2008, 02:00 PM
Thanks Ted

It's working for me too!! :-)
0
Eric Skaggs
Top achievements
Rank 2
answered on 14 Oct 2009, 05:51 PM
How come there's not been any follow-up on this?  What's the appropriate way to do this?

I've gone through the documentation to which you've already provided a link. 

Eric Skaggs
Tags
Grid
Asked by
ldc0618
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ted
Top achievements
Rank 1
Jeremy Wadsworth
Top achievements
Rank 1
Guss
Top achievements
Rank 2
Eric Skaggs
Top achievements
Rank 2
Share this question
or