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

RadGrid + GridSettingsPersister - Filter States

10 Answers 305 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Guido Tapia
Top achievements
Rank 1
Guido Tapia asked on 16 Apr 2009, 02:01 AM
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

10 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 21 Apr 2009, 02:58 PM
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.
0
Guido Tapia
Top achievements
Rank 1
answered on 21 Apr 2009, 08:37 PM
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
0
Guido Tapia
Top achievements
Rank 1
answered on 22 Apr 2009, 08:45 PM
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;

}

}

0
Eric Skaggs
Top achievements
Rank 2
answered on 14 Oct 2009, 05:22 PM
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
0
Pavlina
Telerik team
answered on 19 Oct 2009, 02:42 PM
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.
0
Robert Noakes
Top achievements
Rank 1
answered on 04 Apr 2010, 06:40 AM
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;

 

    }

}

0
Pavlina
Telerik team
answered on 05 Apr 2010, 10:22 AM
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.
0
Mario
Top achievements
Rank 1
answered on 26 Jul 2010, 08:30 PM
Great snippet.... works like a charm
0
Erik
Top achievements
Rank 2
answered on 03 Apr 2011, 02:53 PM
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
0
Erik
Top achievements
Rank 2
answered on 03 Apr 2011, 03:03 PM
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
Tags
Grid
Asked by
Guido Tapia
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Guido Tapia
Top achievements
Rank 1
Eric Skaggs
Top achievements
Rank 2
Robert Noakes
Top achievements
Rank 1
Mario
Top achievements
Rank 1
Erik
Top achievements
Rank 2
Share this question
or