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

How to reset RadGrid columns to default visibility

11 Answers 474 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tushar
Top achievements
Rank 1
Tushar asked on 11 Jun 2014, 07:53 AM
Hello,
I have added custom functionality to my RadGrid to persist grid column visibility when user toggles column visibility from "Columns" context menu.
So whenever user comes back to that page, same columns are displayed as last time.

I am applying persisted settings in Grid prerender event by calling following function:
        private void ApplyGridSettings()
        {
            var persistenceHelper = new PersistenceHelper();
            var settings = persistenceHelper.GetGridPersistenceSettings(this.ClientID);
            if (settings != null)
            {
                foreach (var columnSetting in settings.ColumnsSettings)
                {
                    var column = this.Columns.FindByUniqueNameSafe(columnSetting.Column);
                    if (column != null)
                    {
                        column.Display = columnSetting.Visible;
                    }
                }
            }
        }

Now I have added a header context menu "Reset Columns" to remove persisted settings and reset grid columns to default visibility.
I am calling following code on HeaderMenu click:

        private void HeaderContextMenu_ItemClick(object sender, RadMenuEventArgs e)
        {
            switch (e.Item.Text)
            {
                case "Reset Columns":
                    var persistenceHelper = new PersistenceHelper();
                    persistenceHelper.ResetGridColumns(this.ClientID);
                    this.MasterTableView.EnableColumnsViewState = false;
                    this.MasterTableView.Rebind();
                    break;

                default:
                    break;
            }
        }

I thought after rebinding the grid will reset grid columns, but it is not working.
Can anyone please suggest how to reset grid columns visibility?

11 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 13 Jun 2014, 09:56 AM
Hi Tushar,

I recommend you examine the following online demo which demonstrates how you can easily save and restore RadGrid settings by using the Persistence Framework:
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/persisting-grid-settings/defaultcs.aspx?product=grid

It also shows how you can save/restore grid columns visibility.

Regards,

Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Curtis
Top achievements
Rank 1
answered on 08 Dec 2014, 10:09 PM
However, this demo doesn't show how to reset the columns visibility. If I click Clear, the columns I once hid are now not visible as they should be by default.

How does one reset the grid columns settings (display, visibility, width, etc)?
0
Pavlina
Telerik team
answered on 11 Dec 2014, 03:28 PM
Hello,

Indeed you are right that the grid does not reset columns visibility when Clear button is clicked. However, this is not related to the persistence framework but is rather demo configuration problem which will be fixed as soon as possible. I will get back to you once the example is updated. Please excuse us for the inconvenience caused.

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Curtis
Top achievements
Rank 1
answered on 11 Dec 2014, 05:11 PM
Thank you very much Pavlina.

I look forward to seeing how to best achieve having all the columns go back to their default state (display, visibility, width, orderindex, etc) as set in the ASPX file. The way I did it was by clearing the persistence and then completely reloading the page but I was hoping there would be a away via AJAX.

Curtis
0
Pavlina
Telerik team
answered on 16 Dec 2014, 04:46 PM
Hello,

If you can send us your exact scenario via a formal support ticket we would be able to get better understanding what you are trying to achive and if possible provide a solution via AJAX.

I am looking forward to your reply.

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Vasssek
Top achievements
Rank 1
answered on 02 Sep 2016, 11:24 PM

Hello,

I would like to know how to reset controls (RadGrid, combobox) to its default state - before applied persistence settings...

In the example mentioned above, the clear button still doesn't restore grid to default state :-(

Thank you

Vasssek

0
Eyup
Telerik team
answered on 07 Sep 2016, 01:49 PM
Hi Vasssek,

You can try the following approach to achieve this requirement:
http://www.telerik.com/forums/reset-the-grid-setting

I hope this will prove helpful.

Regards,
Eyup
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Vasssek
Top achievements
Rank 1
answered on 07 Sep 2016, 09:00 PM

Hello,

thank you for that advice, but I'm afraid it's not on 100 % what I'm looking for. Let's say I hide some columns, then save grid state through persistance and now I want to show initial grid state (show previously hidden columns, etc.)  - as if Page life cycle is in !Page.IsPostBack state.  AFAIK - it can be done via Response.Redirect but I want to do it through AJAX...

Please help.

Regards

Vasssek

0
Konstantin Dikov
Telerik team
answered on 12 Sep 2016, 07:16 AM
Hello,

You can save the default state of RadGrid with another storage key and load the state using that default key once you need to reset the state to the default settings.

Hope this helps.


Regards,
Konstantin Dikov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Vasssek
Top achievements
Rank 1
answered on 12 Sep 2016, 03:19 PM

Hello,

thank you for your suggestion. To be honest, I did it this way. Store default settings to some SQL column and user change settings to another one. I just want to know if persistance manager didn't have such method to be called and than each control in page will be in state as when page is first time loaded.

Please consider to add this kind of method to some next build...

Thank you

Vasssek

0
Konstantin Dikov
Telerik team
answered on 15 Sep 2016, 10:47 AM
Hi Vasssek,

The Persistence manager will save the state to a particular key it the current configuration of the controls and the requirement that you have could be achieved only manually, by saving the initial state to a specific key (for example, "default").


Kind Regards,
Konstantin Dikov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Tushar
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Curtis
Top achievements
Rank 1
Vasssek
Top achievements
Rank 1
Eyup
Telerik team
Konstantin Dikov
Telerik team
Share this question
or