Bug Report T295446
Visible to All Users

GridView - The AllowFixedGroups property causes a JavaScript error in the GridViewFixedGroupsHelper.SetGroupRowCellsWidth method when a pager is enabled

created 9 years ago (modified 9 years ago)

I was initially going to submit this ticket for a problem I had getting my grid to call my EndCallBack function, but I eventually discovered the problem was actually caused by a JS error within GridViewFixedGroupsHelper.SetGroupRowCellsWidth JS function which occurring before the call to my EndCallBack function (wgEnd).

The error occurs when I set the settings.SettingsBehavior.AllowFixedGroups = true. If I set to false, the error doesn't occur, but I don't get the functionality that I'm looking for. For me, other than the EndCallBack not firing as needed, everything else with the grid behaves normally; paging works, sorting works, etc.

My partial view for the grid has the following (trimmed down for readability):

C#
var grid = Html.DevExpress().GridView<CustomModel>(settings => { settings.Name = "wg"; settings.SettingsSearchPanel.Visible = false; settings.CallbackRouteValues = new { Controller = "Home", Action = "wgPartial", w = ViewBag.Id }; settings.ClientSideEvents.Init = "wgInit"; settings.ClientSideEvents.BeginCallback = "wgBegin"; settings.ClientSideEvents.EndCallback = "wgEnd"; settings.KeyFieldName = "Id"; settings.SettingsLoadingPanel.Mode = GridViewLoadingPanelMode.Default; settings.Settings.ShowFilterRow = false; settings.Settings.VerticalScrollableHeight = 600; settings.Settings.VerticalScrollBarMode = ScrollBarMode.Visible; settings.Settings.UseFixedTableLayout = true; settings.SettingsPager.Mode = GridViewPagerMode.ShowPager; settings.SettingsPager.PageSize = 30; settings.Width = Unit.Percentage(100); settings.Styles.Table.CssClass = "table table-bordered"; settings.Styles.Header.CssClass = "header"; settings.SettingsBehavior.AllowFixedGroups = true; settings.SettingsBehavior.AllowSelectByRowClick = false; settings.SettingsBehavior.AutoExpandAllGroups = true; settings.SettingsBehavior.AllowGroup = false; settings.SettingsBehavior.AllowDragDrop = false; settings.SettingsBehavior.AllowSelectByRowClick = false; settings.SettingsBehavior.AllowSelectSingleRowOnly = false; settings.SettingsDetail.ShowDetailRow = true; settings.SettingsDetail.ShowDetailButtons = false; settings.SettingsDetail.AllowOnlyOneMasterRowExpanded = false; settings.Columns.Add(m => { m.FieldName = "Prop1"; m.GroupIndex = 0; m.Caption = "Prop #1"; m.SetGroupRowTemplateContent(diTemplate => { string name = ((string)DataBinder.Eval(diTemplate.DataItem, nameof(CustomModel.Prop1))); ViewContext.Writer.Write(string.IsNullOrEmpty(name) ? "<i>(No 1 Specified)</i>" : name); }); }); settings.Columns.Add(m => { m.FieldName = "Prop2"; m.GroupIndex = 1; m.Caption = "Prop #2"; m.SetGroupRowTemplateContent(diTemplate => { string name = ((string)DataBinder.Eval(diTemplate.DataItem, nameof(CustomModel.Prop2))); ViewContext.Writer.Write(string.IsNullOrEmpty(name) ? "<i>(No 2 Specified)</i>" : name); }); }); settings.Columns.Add(m => { m.FieldName = "Prop3"; m.Caption = "Prop #3"; }); settings.Columns.Add(m => { m.FieldName = "Prop4"; m.Caption = "Prop #4"; }); }); @grid.Bind(Model).GetHtml()

With that I get a "Uncaught TypeError: Cannot read property 'style' of undefined" JS error within GridViewFixedGroupsHelper.SetGroupRowCellsWidth:

JavaScript
groupRow.cells[level + 1].style.width = totalWidth - ASPx.GetLeftRightBordersAndPaddingsSummaryValue(groupRow.cells[level + 1]) + "px";

"groupRow.cells" is an HTMLCollection with one element and "level" == 0". groupRow.cells[0] is the grouped header with "(No 1 Specified)" in it. "level + 1" is undefined, naturally, as the collection only has one element. Once that error is hit, my EndCallBack method never gets called again… unless oddly enough I'm switching from a page > 1 back to page == 1.

Comments (3)
Alessandro (DevExpress Support) 9 years ago

    Hi,

    I have created a small sample project that covers your scenario and operates correctly as shown in the attached screencast. I hope reviewing it will help you find a solution to this problem. If this does not help, please update my sample to illustrate the problem. Then, I will see what is going wrong and do my best to find a solution.

    DW DW
    Donovan Woodside 9 years ago

      I can replicate the problem in your sample if I adjust one of the grouped columns with the following:
      settings.Columns.Add(column => {
      column.FieldName = "UnitsOnOrder";
      column.GroupIndex = 1;
      column.SetGroupRowTemplateContent(diTemplate =>
      {
      short? units = ((short?)DataBinder.Eval(diTemplate.DataItem, "UnitsOnOrder"));
      ViewContext.Writer.Write(!units.HasValue || units == 0 ? "<i>No Orders</i>" : units.ToString());
      });
      });
      It's the overriding of the text in the group header which causes the problem. The GroupText property is read-only, so I resorted to setting it via the SetGroupRowTemplateContent function.
      I've attached a screencast of the error occurring.

      DevExpress Support Team 9 years ago

        Hello,

        I was able to reproduce this issue on my side and passed this ticket to our developers.
        We will update this ticket as soon as we have results.

        Answers approved by DevExpress Support

        created 9 years ago

        We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

        Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

          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.