RadGrid + GridSettingsPersister - Filter States

11 posts, 0 answers
  1. Guido Tapia
    Guido Tapia avatar
    87 posts
    Member since:
    Jul 2012

    Posted 15 Apr 2009 Link to this post

    Hi,

    I'm currently playing around with GridSettingsPersister (with latest version of RadGrid) and I have a bit of a problem with the filter states.  I have BoundColumns with the following properties:
      AutoPostBackOnFilter = true;
      CurrentFilterFunction = GridKnownFunction.Contains;
      ShowFilterIcon = false;

    But when I load the state of these filters in Page_Init the filtered expressions are added correctly to the grid but the file TextBox remains empty, giving the user no indication that the grid is sorted.

    Does anyone have a workaround for this?

    Thanks

    Guido Tapia
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 21 Apr 2009 Link to this post

    Hello Guido,

    I hope you are trying to save the run time settings of RadGrid. If so go through the following help document and see whether it helps.
    Saving grid settings on a per user basis

    Sincerely yours,
    Pavlina
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Guido Tapia
    Guido Tapia avatar
    87 posts
    Member since:
    Jul 2012

    Posted 21 Apr 2009 Link to this post

    That is the code I am using already.  

    Please read my question again:

    "I'm currently playing around with GridSettingsPersister (with latest version of RadGrid) and I have a bit of a problem with the filter states.  I have BoundColumns with the following properties:
      AutoPostBackOnFilter = true;
      CurrentFilterFunction = GridKnownFunction.Contains;
      ShowFilterIcon = false;

    But when I load the state of these filters in Page_Init the filtered expressions are added correctly to the grid but the file TextBox remains empty, giving the user no indication that the grid is sorted.

    Does anyone have a workaround for this?"



    So, everything is saved and loaded correctly, but the filter boxes do not display the filtered value.

    Thanks
  5. Guido Tapia
    Guido Tapia avatar
    87 posts
    Member since:
    Jul 2012

    Posted 22 Apr 2009 Link to this post

    I have a hacky workaround for this:

    Thanks

    Guido
    ----------------------------------------

    private

     

    void PagePreRender() {

     

     

    if (!IsPostBack) { PopulateFilterBoxes(); }

     

    }

     

    private

     

    void PopulateFilterBoxes()

     

    {

     

        GridFilteringItem gfi = (GridFilteringItem) rgEntityList.MasterTableView.GetItems(GridItemType.FilteringItem)[0];

     

     

        string allExpressions = rgEntityList.MasterTableView.FilterExpression;

     

     

        string[] expressions = allExpressions.Split(new []{" AND "}, StringSplitOptions.RemoveEmptyEntries);

     

     

        foreach (string exp in expressions) {

     

     

            Match m = Regex.Match(exp, @"\[(.+)\] .* \'\%(.+)\%'");

     

     

            string dataField = m.Groups[1].Value;

     

     

            string value = m.Groups[2].Value;

     

     

     

            GridBoundColumn column = null;

     

     

            foreach (GridColumn gc in rgEntityList.Columns) {

     

     

                if (!(gc is GridBoundColumn)) { continue; }

     

     

                GridBoundColumn gbc = (GridBoundColumn) gc;

     

     

                if (dataField.Equals(gbc.DataField)) {

     

                    column = gbc;

     

                    break;

     

                }

            }

     

            if (column == null) continue;

     

     

            TableCell td = gfi[column.UniqueName];

     

     

            TextBox tb = (TextBox) td.Controls[0];

     

            tb.Text = value;

    }

    }

  6. Eric Skaggs
    Eric Skaggs avatar
    39 posts
    Member since:
    Nov 2008

    Posted 14 Oct 2009 Link to this post

    Pavlina,

    Is there a way to keep the value of the filter in the column's textbox?  I noticed you never got back to Guido on this.  I'd like to see the official way to do this since I'm experiencing the same issue.

    Here's the official code that I'm using (the same code you linked to earlier in this thread):
        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];  
                int columnsLength = gridInstance.MasterTableView.Columns.Count + gridInstance.MasterTableView.AutoGeneratedColumns.Length;  
                ArrayList allColumns = new ArrayList(columnsLength);  
                allColumns.AddRange(gridInstance.MasterTableView.Columns);  
                allColumns.AddRange(gridInstance.MasterTableView.AutoGeneratedColumns);  
     
                /******************  Save filters  *******************/ 
                gridSettings[3] = (object)gridInstance.MasterTableView.FilterExpression;               
                //save the visible/displayed columns settings and current filter value/current filter function              
                ArrayList visibleColumns = new ArrayList(columnsLength);              
                ArrayList displayedColumns = new ArrayList(columnsLength);              
                Pair[] columnFilter = new Pair[columnsLength];  
                int i = 0;  
                foreach (GridColumn column in allColumns)   
                {   
                    columnFilter[i] = new Pair(column.CurrentFilterFunction, column.CurrentFilterValue);   
                    visibleColumns.Add(column.Visible);   
                    displayedColumns.Add(column.Display);  
                    i++;   
                }   
                gridSettings[4] = visibleColumns;   
                gridSettings[5] = displayedColumns;   
                gridSettings[6] = columnFilter;               
                /*****************************************************/ 
     
                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);  
                int columnsLength = this.gridInstance.MasterTableView.Columns.Count + this.gridInstance.MasterTableView.AutoGeneratedColumns.Length;  
                ArrayList allColumns = new ArrayList(columnsLength);  
                allColumns.AddRange(this.gridInstance.MasterTableView.Columns);  
                allColumns.AddRange(this.gridInstance.MasterTableView.AutoGeneratedColumns);  
     
                /******************  Load filter expression  *******************/ 
                this.gridInstance.MasterTableView.FilterExpression = (string)gridSettings[3];  
     
                //Load visible/displayed columns and their current filter values/current filter functions  
                ArrayList visibleCols = (ArrayList)gridSettings[4];  
                ArrayList displayedColumns = (ArrayList)gridSettings[5];  
                Pair[] columnFilter = (Pair[])gridSettings[6];  
     
                int j = 0;  
     
                foreach (GridColumn column in allColumns)  
                {  
                    column.CurrentFilterFunction = (GridKnownFunction)columnFilter[j].First;  
                    column.CurrentFilterValue = (string)columnFilter[j].Second;  
                    column.Visible = (bool)visibleCols[j];  
                    column.Display = (bool)displayedColumns[j];  
                    j++;  
                }  
                /***************************************************************/ 
            }  
        } 

    I am calling Loadsettings on PageInit, but what I'm seeing is that the variable allColumns is being returned with 0 columns because my columns are autogenerated and apparently at this point, they are not accessible.

    If I call Loadsettings from the RadGrid's prerender method, allColumns is returned with the correct number of columns, but I don't seem to be able to successfully set column filter values at that time.

    Suggestions?

    Thank you,

    Eric Skaggs
  7. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 19 Oct 2009 Link to this post

    Hello Eric,

    Unfortunately we can not determine the exact cause for the issue you encountered without a working application which demonstrate it. At this point I will ask you to open a formal support ticket and send us a simple working project with reproduced this erroneous behavior. We will examine it in detail and will get back to you with our findings.

    Regards,
    Pavlina
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Robert Noakes
    Robert Noakes avatar
    1 posts
    Member since:
    Mar 2010

    Posted 04 Apr 2010 Link to this post

    I ran into this issue as well, and think I have found the solution if you haven't figured it out yet. You need to make sure the data is bound to the table before you attempt to load the settings. I also added a little custom code because RadNumericTextBoxes and columns without filters were causing errors. Replace:

    (filterItem[column.UniqueName].Controls[0] as TextBox).Text = (string)columnFilter[a].Second;

    With this:

    if

     

    (filterItem[column.UniqueName].Controls.Count > 0)

     

    {

     

        Control c = filterItem[column.UniqueName].Controls[0];

     

     

        string text = (string)columnFilter[a].Second;
       

     

     

        if (c.GetType() == typeof(TextBox))

     

        {

            ((

    TextBox)c).Text = text;

     

        }

     

        else if (c.GetType() == typeof(RadNumericTextBox))

     

        {

            ((

    RadNumericTextBox)c).Text = text;

     

        }

    }

  9. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 05 Apr 2010 Link to this post

    Hi Robert,

    Thank you for sharing your solution in this forum thread - thus you can help other community members which search similar type of functionality.

    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.
  10. Mario
    Mario avatar
    24 posts
    Member since:
    Apr 2009

    Posted 26 Jul 2010 Link to this post

    Great snippet.... works like a charm
  11. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 03 Apr 2011 Link to this post

    Hi All,

    I have a radgrid that is created fully in code. I used this code snip, and it works, only the first time it has a strange effect, after postback all is ok. any one a idea what i must do?

    I create the grid in the Init, save settings it in load (if isPostBack) and load settings it in Prerender (if not is postback)

    Regards,

    Erik
  12. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 03 Apr 2011 Link to this post

    Ow, ok. I  read something about datasource must be connected, I use the NeedDataSource event, when I Load the settings in that event, it  works fine!

    Erik
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017