Wrong logic in GetStyles method in RadzenDataGridColumn.razor.cs #1279

Closed
opened 2026-01-29 17:51:29 +00:00 by claunia · 1 comment
Owner

Originally created by @phantomkingx on GitHub (Jun 30, 2024).

The 'colgroup' elements are getting a width applied when resizing columns in RadzenDataGrid. This is a problem when loading previously saved datagrid settings immediately after resizing the column. The column width is forced to the previously resized width of the 'colgroup', and the settings width applied to the 'th' element is being overridden.

At the very top of the GetStyles method the logic is:

if (!string.IsNullOrEmpty(width) && !isForCol)

It appears there is an attempt to prevent applying width to the colgroup, however the correct logic should be like this:

if (!string.IsNullOrEmpty(width))

The problem appears to be the browser sets the manually sized width of the colgroup and nothings removes it when the settings are applied. I tested my change and it appears to work for my use case however I don't know the reasoning of the current logic to not apply width to the colgroup.

Here is how the current method looks like for context:

public virtual string GetStyle(bool forCell = false, bool isHeaderOrFooterCell = false, bool isForCol = false)
{
    var style = new List<string>();

    var width = GetWidthOrGridSetting()?.Trim();

    if (!string.IsNullOrEmpty(width) && !isForCol)
    {
        style.Add($"width:{width}");
    }

    ...
Originally created by @phantomkingx on GitHub (Jun 30, 2024). The 'colgroup' elements are getting a width applied when resizing columns in RadzenDataGrid. This is a problem when loading previously saved datagrid settings immediately after resizing the column. The column width is forced to the previously resized width of the 'colgroup', and the settings width applied to the 'th' element is being overridden. At the very top of the GetStyles method the logic is: ``` if (!string.IsNullOrEmpty(width) && !isForCol) ``` It appears there is an attempt to prevent applying width to the colgroup, however the correct logic should be like this: ``` if (!string.IsNullOrEmpty(width)) ``` The problem appears to be the browser sets the manually sized width of the colgroup and nothings removes it when the settings are applied. I tested my change and it appears to work for my use case however I don't know the reasoning of the current logic to not apply width to the colgroup. Here is how the current method looks like for context: ``` public virtual string GetStyle(bool forCell = false, bool isHeaderOrFooterCell = false, bool isForCol = false) { var style = new List<string>(); var width = GetWidthOrGridSetting()?.Trim(); if (!string.IsNullOrEmpty(width) && !isForCol) { style.Add($"width:{width}"); } ... ```
Author
Owner

@phantomkingx commented on GitHub (Jun 30, 2024):

Got it working with old code, closing.

@phantomkingx commented on GitHub (Jun 30, 2024): Got it working with old code, closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1279