[bp:GridViewRowSelectColumn] show/hide bug

There is a bug in the bp:GridViewRowSelectColumn implementation that prevents it from successfully being hidden or removed from a GridView.

I have created a page (linked below) that demonstrates quite a few different attempted methods to show/hide the column.

Please run the example and observe the behavior.

What I would list as additional functional requirements for this column would be:

  1. The column can be added/removed without changing the order of all other columns. (It is currently changing the order of columns under some circumstances.)
  2. The column can be removed without consuming space in the grid when not actually present.
  3. Other columns can be added/removed without causing column reordering or space wasted for non-existent columns.

ShowHideColumn.dothtml (9.6 KB)
ShowHideColumnViewModel.cs (10.3 KB)

From what I can tell, the issue seems to come from the hard-coded width property of “30px” that is being set in the BuildCol(() method. When the column’s visibility is set to false, the width property (even if set to a different value) is causing the column to still take up space on the page.

Looking at the developer tools while the column is “hidden” you can see that the width element.style value is set to “30px” in the <colgroup> for the selection column. If you uncheck/remove that setting the table adjusts and is then correct. Either removing the width style property or adding display:none when the column is meant to be hidden seems to fix the issue.

Note that when a bp:GridViewRowSelectColumn is not included in the grid, showing/hiding columns seems to work correctly.

I created an issue here.

1 Like

Thanks for creating the issue, we’d forget about it here

1 Like

For those dealing with this issue as well, I think I came up with a workaround.

I created a new version of the GridViewRowSelectColumn control in my project as follows. Basically all it does it byass the default 30px width property when Visible is set to false.

A real fix is still needed, but I think this will at least make the column usable when needing show/hide functionality until it is.

Note: I have not done extensive testing on this yet. There may be a better solution.

public class GridViewRowSelectColumn : DotVVM.BusinessPack.Controls.GridViewRowSelectColumn
{
    public GridViewRowSelectColumn(BindingCompilationService bindingService) : base(bindingService)
    {
    }

    public override void BuildCol(HtmlGenericControl col)
    {
        if (IsPropertySet(GridViewColumn.VisibleProperty))
        {
            if ((bool)GetValue(GridViewColumn.VisibleProperty))
                base.BuildCol(col);
        }
        else
        {
            base.BuildCol(col);
        }
    }
}