Ticket Q531390
Visible to All Users
Duplicate

GridView - How to load saved Client Layout data in Custom Model Binding mode

created 11 years ago

We are using the MVC Extensions GridView with custom model binding to populate our grid. I have seen the post demonstrating that in the grid settings you can save/load the layout via the settings in the view model such as this:
Code Example 1 ( in the grid view setting)

C#
settings.ClientLayout = (o, e) => { if (layoutData != null) { e.LayoutData = layoutData; } };

However, this occurs after the actual binding of the grid which is happening on the controller action with:
Code Example 2 (In the controller action for "ViewModel")

C#
viewModel.ProcessCustomBinding( binding.GetDataRowCount, binding.GetData, binding.GetSummaryValues, binding.GetGroupingInfo, binding.GetUniqueHeaderFilterValues );

The ClientLayout cannot be called before the actual binding to the view model. How can I set the layout data before I ProcessCustomBinding?

Comments (3)
DevExpress Support Team 11 years ago

    Hi Steven,
    As you noted, the ClientLayout even is fired after databinding because it is necessary that the grid has data once the saved layout is being applied.
    I will need some additional time to further discuss this behavior with my R&D team to find a possible workaround.
    In the meantime, would you please clarify the reason for setting the layout before databinding?
    I greatly appreciate your time and cooperation.

      Hello Kate,
      Our requirements specify that the end-user has the ability to save the report state, including showing/hiding columns, sorting, grouping, filters, etc. After it has been saved, using the Layout property, they can click on that "Report" and it will load it to the previous saved state.
      Another part of our requirements say that we need to be distributive in our development using a n-tier architecture that separates our database from our front-end projects via WCF. Because we cannot expose the DBContext, we are required to do custom binding via the ProcessCustomBinding.
      In addition, our queries could return as much as 100,000+ records and we are taking great detail that we are only working with visible records.
      So, when the user clicks on a saved query, we want the grid to call back to the database with all the filters, sorting and grouping already applied.
      Ideally, I would imagine there is some solution that allows for use to set the layout data on the client and then have the grid refresh so that as it hit the action, the view model would already have all the filters, grouping and settings applied so that we know what to grab from the DB.

      DevExpress Support Team 11 years ago

        Hi Steven,
        Thank you for the clarification.
        I forwarded this ticket to my R&D team for further analysis. We will update this thread once we have results to report.
        I greatly appreciate your patience.

        Answers approved by DevExpress Support

        created 8 years ago (modified 8 years ago)

        I've finally broken down and decided to serialize and save the GridViewModel as well as the layout. By using the saved GridViewModel I'm able to process my custom binding and get the proper data in one callback and then the PreRender and BeforeGetCallbackResult use the layout  to handle the visual aspects of the grid.

          Comments (1)
          DevExpress Support Team 8 years ago

            Hello Reuven,

            Saving and loading a custom layout is not fully supported yet, but I am happy to hear that you have found an appropriate workaround.

            created 11 years ago (modified 11 years ago)

            Hello Steven,
            We have discussed this issue. The built-in client layout data is not used in Custom Data Binding mode because a resultant data set is obtained in the Controller, but GridView is created in the PartialView when the data set cannot be changed.
            We have found only one solution to this issue. Implement the following delegate in GridView settings:

            C#
            settings.ClientLayout = (s, e) => { if (e.LayoutMode == ClientLayoutMode.Saving) { Session["gvSettings"] = e.LayoutData; } else { if (Session["gvSettings"] != null) { e.LayoutData = Session["gvSettings"].ToString(); } } };

            You can use any appropriate storage to keep the LayoutData string.
            Add the following client-side event handler:

            C#
            settings.ClientSideEvents.Init = "function(s, e) { s.PerformCallback(); }";

            On the first page opening, the GridView will be rendered with the correct layout with an invalid data set. For example, the grid will have a filter expression, column sort info, grouping and paging info if the loaded Layout Data contains it. But, data rows will not reflect these modifications since they are applied after data is obtained.
            When the Init event is raised, ASPxGridView immediately sends a callback to the server. Client layout data will be also sent to the server and will be available in the Controller via the GridViewColumnState parameter.
            This solution requires sending an additional callback, but there is no other more effective way to accomplish this task.

              Show previous comments (9)
              DevExpress Support Team 6 years ago

                Hi Venkata,

                Layout persistence is still partially supported in Custom Data Binding. The described workaround works well unless you need to sort, filter, etc. data on the first load.

                  Hi,

                  We're facing the same issue now. We need to use custom binding to handle the loading of huge data, while also persist the layout that user defined, including column order, grouping, sorting and filtering.

                  We are seriously in need for a solution. We're fine with sending an additional callback as per the your answer, but performing callback on init will actually cause the custom layout to be overwritten by the "default" layout.

                  Is there a better moment to perform the callback?

                  DevExpress Support Team 6 years ago

                    Hello,

                    I've created a separate ticket on your behalf (T735863: The saveg GridView layout is overwritten by default one on first load). It has been placed in our processing queue and will be answered shortly.

                    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.