Save Filter

8 posts, 0 answers
  1. ldc0618
    ldc0618 avatar
    8 posts
    Member since:
    Jun 2007

    Posted 23 Apr 2008 Link to this post

    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!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Apr 2008 Link to this post

    Hi,

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

    Thanks
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ted
    Ted avatar
    47 posts
    Member since:
    Jan 2008

    Posted 10 Jun 2008 Link to this post

    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?

  5. Jeremy Wadsworth
    Jeremy Wadsworth avatar
    41 posts
    Member since:
    Mar 2006

    Posted 21 Jun 2008 Link to this post

    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.
  6. Guss
    Guss avatar
    48 posts
    Member since:
    Apr 2008

    Posted 30 Jun 2008 Link to this post

    I have also implimented this solution, AND would also like to know how to put the "FA" back in the filtertextbox.
  7. Ted
    Ted avatar
    47 posts
    Member since:
    Jan 2008

    Posted 30 Jun 2008 Link to this post

    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++;

    }

    }

    }

    }

  8. Guss
    Guss avatar
    48 posts
    Member since:
    Apr 2008

    Posted 30 Jun 2008 Link to this post

    Thanks Ted

    It's working for me too!! :-)
  9. Eric Skaggs
    Eric Skaggs avatar
    39 posts
    Member since:
    Nov 2008

    Posted 14 Oct 2009 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017