[PR #1408] feat: DataGridSettings with CustomFilterExpression #2723

Open
opened 2026-01-29 18:20:11 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/radzenhq/radzen-blazor/pull/1408

State: closed
Merged: No


CustomFilterExpression wasn't included in DataGridSettings. Added in this PR,

PR seems to be big but there are almost no changes.
DataGridSettings,Columns have default value Enumerable.Empty<>() which can save us checking if columns == null (not expected anyway).

var gridColumn = ColumnsCollection.Where(c => !string.IsNullOrEmpty(column.Property) && c.Property == column.Property).FirstOrDefault() ??
                                ColumnsCollection.Where(c => !string.IsNullOrEmpty(column.UniqueID) && c.UniqueID == column.UniqueID).FirstOrDefault();

was extracted to method

        private RadzenDataGridColumn<TItem> GetColumnByPropertyAndUniqueIdOrDefault(DataGridColumnSettings dataGridColumnSettings)
        {
            return ColumnsCollection
                .Where(c => !string.IsNullOrEmpty(dataGridColumnSettings.Property) && c.Property == dataGridColumnSettings.Property)
                .FirstOrDefault() ?? ColumnsCollection
                    .Where(c => !string.IsNullOrEmpty(dataGridColumnSettings.UniqueID) && c.UniqueID == dataGridColumnSettings.UniqueID)
                    .FirstOrDefault();
        }

and used
var gridColumn = GetColumnByPropertyAndUniqueIdOrDefault(column);
because there was the same code duplicated.

if (SettingsChanged.HasDelegate)
{
    // content of the method
}

changed to

if (SettingsChanged.HasDelegate == false)
{
   return;
}

// content of the method

to make code more readable

the same with

if (gridColumn == null)
{
    continue;
}

which is reason why the PR looks so big

Only signicificant change is adding this:

if (gridColumn.GetCustomFilterExpression() != column.CustomFilterExpression &&
    !string.IsNullOrEmpty(column.CustomFilterExpression) &&
    gridColumn.FilterOperator == FilterOperator.Custom)
{
    gridColumn.SetCustomFilterExpression(column.CustomFilterExpression);
    shouldUpdateState = true;
}
**Original Pull Request:** https://github.com/radzenhq/radzen-blazor/pull/1408 **State:** closed **Merged:** No --- CustomFilterExpression wasn't included in DataGridSettings. Added in this PR, PR seems to be big but there are almost no changes. DataGridSettings,Columns have default value Enumerable.Empty<>() which can save us checking if columns == null (not expected anyway). ``` var gridColumn = ColumnsCollection.Where(c => !string.IsNullOrEmpty(column.Property) && c.Property == column.Property).FirstOrDefault() ?? ColumnsCollection.Where(c => !string.IsNullOrEmpty(column.UniqueID) && c.UniqueID == column.UniqueID).FirstOrDefault(); ``` was extracted to method ``` private RadzenDataGridColumn<TItem> GetColumnByPropertyAndUniqueIdOrDefault(DataGridColumnSettings dataGridColumnSettings) { return ColumnsCollection .Where(c => !string.IsNullOrEmpty(dataGridColumnSettings.Property) && c.Property == dataGridColumnSettings.Property) .FirstOrDefault() ?? ColumnsCollection .Where(c => !string.IsNullOrEmpty(dataGridColumnSettings.UniqueID) && c.UniqueID == dataGridColumnSettings.UniqueID) .FirstOrDefault(); } ``` and used `var gridColumn = GetColumnByPropertyAndUniqueIdOrDefault(column);` because there was the same code duplicated. ``` if (SettingsChanged.HasDelegate) { // content of the method } ``` changed to ``` if (SettingsChanged.HasDelegate == false) { return; } // content of the method ``` to make code more readable the same with ``` if (gridColumn == null) { continue; } ``` which is reason why the PR looks so big Only signicificant change is adding this: ``` if (gridColumn.GetCustomFilterExpression() != column.CustomFilterExpression && !string.IsNullOrEmpty(column.CustomFilterExpression) && gridColumn.FilterOperator == FilterOperator.Custom) { gridColumn.SetCustomFilterExpression(column.CustomFilterExpression); shouldUpdateState = true; } ```
claunia added the pull-request label 2026-01-29 18:20:11 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#2723