Current filter:
                                You should refresh the page.
                                Support Center
                                0
                                  • Hi,
                                    We use a lot of MVC Grids in our application. I figured out that posting the form the grid is in, uploads the settings to the server. It seems to do this "magically" though since we never seem to get the settings object serverside. It still works when Exporting to PDF or XLS though.

                                    How do we intercept and save the GridView settings?

                                    How do we load them again?

                                0

                                Hi Michael,

                                I am afraid this issue is not quite clear. I have tested the online Exporting to PDF, XLS, XLSX and RTF example and it appears that GridView exports exactly the same configurations that a user sees on a screen.

                                If you mean that you wish to store GridView settings when an end-user re-opens the browser, I suggest that you turn on the GridViewSettings.SettingsCookies property.

                                Thanks,
                                Marion

                                0

                                Yes the Export renders the grid exactly like it looks. This leads me to believe that the settings are sent to the server and processed somewhere in the background.

                                We would like to "catch" these settings, save them and load them the next time the same user logs on.

                                Some users would want to have more than one setting to choose from, so they have different "views" of the same grid and data. This is not possible with the Cookie. The cookie also doesnt support sharing grid settings.

                                In your old WinForms grids we could serialize/export the settings to an XML file which could be stored in a database.

                                0

                                Hello Michael,

                                Thank you for your response. We recommend that you use the built-in functionality for managing GridView layout settings. Please refer to the Save and Restore Layout help topic to learn more on how to use this feature. The described approach is common for both the ASPxGridView control and MVC GridView Extension.

                                Please refer to the Q335692 - GridView - How to persist the GridView state in the XML file report, where we discussed a similar issue in the past.

                                Thanks,
                                Mike

                                P.S. It seems you are using an older build of our components (according to the report's Build field). Please visit our Version Info Page to learn about the most recent versions of our products and obtain instructions on how to update them. Also check the What’s New list to learn more about newly introduced features and issues we have already resolved in the most recent version.

                                0

                                SaveClientLayout is not supported by MVC. Your coleague even says so in the issue you refer to.

                                As for "Save and Restore Layout" article, that requires me to have access to the GridView object, serverside. This is not the case in MVC. None of your examples on mvc.devexpress.com shows this as an option anyway :)

                                Reffering to this issue: http://www.devexpress.com/Support/Center/p/Q335390.aspx the guy never explains where he uses his code snippet (controller, gridViewHelper or something different)

                                How does your export feature get the clientLayout? Its obviously intercepting it via a hidden field during the form post of the grid. But how do i catch it for future use aswell?

                                If i cant, then what string/object should i save to a hidden field and post along with the grid in the form? (the entire ClientGridView javascript object? var dxo = new MVCxClientGridView('gvJournal');)

                                I dont suppose you have a demoproject showing one way of doing it?

                                0

                                Hello Michael,

                                Thank you for your reply.

                                The GridViewSettings class has the GridViewSettings.ClientLayout property. You need to assign a corresponding delegate to the property. The delegate will be called when the grid needs to save or restore its layout. You can implement it in the following manner:

                                [C#]
                                settings.ClientLayout = (sender, e) => { if ((e.LayoutMode == ClientLayoutMode.Loading) && (Session["gridLayout"] != null)) { e.LayoutData = Session["gridLayout"] as string; } else if (e.LayoutMode == ClientLayoutMode.Saving) { Session["gridLayout"] = e.LayoutData; } };

                                You can use any appropriate storage instead of a Session to save the grid layout. I have attached a sample project to illustrate this solution. Let us know if you have any other questions.

                                Best regards,
                                Vladimir

                                0

                                I see, thank you very much.

                                It's not exactly a "pretty" way to do it (it breaks with the MVC pattern) but i guess it could work.

                                Is there a javascript function we can call to perform a callback with/for the clientlayout without actually moving any columns/sorting/grouping?
                                We want our users to be able to save different layouts they set up. So we need to be able to save only certain layouts that come in, at certain times.
                                When a column is finished being moved, it must use some function to make the callback.

                                Also can i find (get or even set) the ClientLayout string locally on the client (using javascript)? This would simplify things a lot and allow us to bypass the Callback entirely.

                                0

                                I was unable to get your sample to work with the version of nwind that MS supplies. But i have added the code im trying to implement in our project into yours.

                                Basicly it uses Sessions to allow the delegate and controller to talk to each other (which is stupid, but i cant find any other way).

                                Once the user presses the button to signal he wants the comming view to be saved, a session variabel is set.

                                All edits to the grid after this point is saved in another Session Variabel.

                                once the user is satisfied that this is the view he wants to save, he clicks the button again. The controller gets the layout data from the Session variabel and stores it whereever.

                                This part works like a charm.

                                I have yet to figure out how to load them again though. I have set up 2 hardcoded (for our grid... you will want to change these) to choose between. But i cant figure out how to get the Grid to load them. If i force a callback by sorting or moving a column it doesnt work.

                                Does this and the project describe what were trying to do?

                                So again my questions are, can we get the layoutString from the DOM or one of your javascript objects? (this would be awesome)
                                Can we set the layoutString for the clientside Grid by Javascript (this would be truly awesome!)
                                Can we force an update/callback without triggering a "save" event aswell?

                                0

                                Hello Michael,

                                Thank you for your reply.

                                There is no special client side method to initiate layout saving. GridView layout is saved during every callback routine. Once GridView layout changes, the control sends a callback and layout is saved on the server side.
                                I suggest you add an additional parameter to the e.customArgs collection in the MVCxClientGridView.BeginCallback event handler to indicate when the layout should be saved. Send the parameter to the View and in the GridViewSettings.ClientLayout delegate, check it. If the parameter is set, you need to allow layout saving, otherwise do not.

                                GridView does not provide any capability to edit layout data on the client side. In the other hand, you can save the layout in a user browser cookie. As a result, you can also modify it using JavaScript methods. Please note, we do not document client-side layout data and do not guarantee that GridView will operate correctly if you change the data manually.

                                Let me know if you need an additional assistance.

                                Best regards,
                                Vladimir

                                0

                                I will try out the cookie. Do you have a link for the docs page where i can see how i can enable it? This page (http://documentation.devexpress.com/#AspNet/DevExpressWebMvcGridViewSettings_SettingsCookiestopic) only seems to provide GET access to it, not enable it to start with.

                                ps. You might want to update this site: http://documentation.devexpress.com/#AspNet/CustomDocument9125
                                I dont really feel like this part is true: Save and Restore Layout - GridView allows you to save the information on its layout to a database, and then restore it.

                                0

                                Hello Michael,

                                Thank you for your feedback.

                                You need to enable cookie saving using the GridViewSettings.SettingsCookies.Enabled setting and set cookie identifier using the GridViewSettings.SettingsCookies.CookiesID property. After that, you can use ASPxClientUtils.GetCookie and ASPxClientUtils.SetCookie methods to get and set the cookie. Please note, we do not recommend modifying the GridView cookies and you must use it at your own risk.

                                I cannot agree with your suggestion about the documentation change. The described approach allows you to store the GridView layout data in any appropriate storage, including Session and data base. Let me know if you need additional assistance in this direction.

                                Best regards,
                                Vladimir

                                0

                                For anyone else who needs this feature, here is how i ended up implementing it.

                                We wanted the ability to save the current layout to the database and give the user the ability to choose between any number of predefined layouts.
                                Add a button and select to your View.

                                Add appropriate jQuery/Javascript functions to talk to your controller:

                                $(document).ready(function () {
                                        $('#SaveCurrentLayout').click(function () {
                                            var url = '@Url.Action("SaveCurrentLayout", "Journal")';
                                            $.ajax({
                                                url: url + "/TestName",
                                                cache: false,
                                                success: function (data) {
                                                    if (data.LayoutStatus == "Saved") {
                                                        $('#LayoutMode').html("Ændringer til griddet er gemt");
                                                        return;
                                                    }
                                                    $('#LayoutMode').html("Fejl");
                                                }
                                            });
                                        });
                                    });
                                
                                    $(document).ready(function () {
                                        $('#ViewLayoutSelection').change(function () {
                                            var ajaxData = $('#ViewLayoutSelection option:selected').val();
                                            var url = '@Url.Action("SelectLayout", "Journal")';
                                            $.ajax({
                                                url: url + "/" + ajaxData,
                                                cache: false,
                                                success: function (data) {
                                                    window.location.reload();
                                                }
                                            });
                                        });
                                    });

                                Note the "reload" on success. Once a user has chosen his/her layout and the cookie is updated by the controller, we need to reload the page to force a callback (Devexpress has no clientside method to force this)

                                In your controller add some methods like these:
                                 

                                [C#]
                                public JsonResult SaveCurrentLayout(IDataProvider dataProvider, String id) { if (this.ControllerContext.HttpContext.Request.Cookies.AllKeys.Contains("JournalGridLayout")) { HttpCookie cookie = this.ControllerContext.HttpContext.Request.Cookies["JournalGridLayout"]; var layoutData = cookie.Value; //TODO: Save layoutData to database or similiar this.ControllerContext.HttpContext.Response.Cookies.Add(cookie); return Json(new { LayoutStatus = "Saved" }, JsonRequestBehavior.AllowGet); } return Json(new { LayoutStatus = "NotSaved" }, JsonRequestBehavior.AllowGet); } public JsonResult SelectLayout(IDataProvider dataProvider, String id) { if (this.ControllerContext.HttpContext.Request.Cookies.AllKeys.Contains("JournalGridLayout")) { HttpCookie cookie = this.ControllerContext.HttpContext.Request.Cookies["JournalGridLayout"]; if (id == "40f3b390-1820-4c34-8d95-d6ee59a90f06") { cookie.Value = "page1%7cgroup1%7csort1%7ca1%7cvisible29%7ct1%7ct2%7ct3%7ct4%7ct5%7ct6%7ct7%7ct8%7ct9%7ct10%7ct11%7ct12%7ct13%7ct14%7ct15%7ct16%7ct17%7ct18%7ct19%7ct20%7ct21%7ct22%7ct23%7ct24%7ct25%7ct26%7ct27%7ct28%7ct0%7cwidth29%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce"; } if (id == "50f3b390-1820-4c34-8d95-d6ee59a90f06") { cookie.Value = "page1%7cgroup3%7csort3%7ca1%7ca10%7ca11%7cvisible29%7ct1%7ct2%7ct3%7ct4%7ct5%7ct6%7ct7%7ct8%7ct9%7ct10%7ct11%7ct12%7ct13%7ct14%7ct15%7ct16%7ct17%7ct18%7ct19%7ct20%7ct21%7ct22%7ct23%7ct24%7ct25%7ct26%7ct27%7ct28%7ct0%7cwidth29%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce%7ce"; } this.ControllerContext.HttpContext.Response.Cookies.Add(cookie); return Json(new { LayoutStatus = "Loaded" }, JsonRequestBehavior.AllowGet); } return Json(new { LayoutStatus = "LayoutNotFound" }, JsonRequestBehavior.AllowGet); }

                                Instead of using hardcoded values, get and save them from the database (or similiar). This just proves the concept.

                                In your Grid, ViewHelper (or PartialView if not using ViewHelpers) set up your grid to use the SetingsCookie:

                                [C#]
                                _settings.SettingsCookies.Enabled = true; _settings.SettingsCookies.CookiesID = "JournalGridLayout";

                                Hope this helps :)

                                0

                                Hello Michael,

                                We are glad to hear that the issue is solved. Your feedback is also appreciated.
                                If you face any difficulty using our components, you are welcome to contact us at any time.

                                Best regards,
                                Vladimir

                                If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2014 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners