How to reset RadGrid columns to default visibility

12 posts, 0 answers
  1. Tushar
    Tushar avatar
    25 posts
    Member since:
    Mar 2014

    Posted 11 Jun 2014 Link to this post

    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?
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 13 Jun 2014 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Curtis
    Curtis avatar
    23 posts
    Member since:
    Jan 2008

    Posted 08 Dec 2014 in reply to Pavlina Link to this post

    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)?
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 11 Dec 2014 Link to this post

    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.

     
  6. Curtis
    Curtis avatar
    23 posts
    Member since:
    Jan 2008

    Posted 11 Dec 2014 in reply to Pavlina Link to this post

    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
  7. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 16 Dec 2014 Link to this post

    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.

     
  8. Vasssek
    Vasssek avatar
    143 posts
    Member since:
    Aug 2010

    Posted 02 Sep in reply to Pavlina Link to this post

    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

  9. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 07 Sep Link to this post

    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.
  10. Vasssek
    Vasssek avatar
    143 posts
    Member since:
    Aug 2010

    Posted 07 Sep in reply to Eyup Link to this post

    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

  11. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 12 Sep Link to this post

    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.
  12. Vasssek
    Vasssek avatar
    143 posts
    Member since:
    Aug 2010

    Posted 12 Sep in reply to Konstantin Dikov Link to this post

    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

  13. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 15 Sep Link to this post

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