Row/column index in datagrid

Hi everyone
Need advice
Have a list of items

public class Schedule:BaseFields
    {
        public string UserID { get; set; }
        public string ShiftID { get; set; }
        public string SubDepartmentID { get; set; }
        public DateTime Date { get; set; }
        public TimeOnly Start { get; set; }
        public TimeOnly End { get; set; }
        public bool IsActive { get; set; }
        public int Changes { get; set; }
        public UserInformation ShiftUser { get; set; }
        public WorkShift Shift { get; set; }
        public SubDepartment SubDepartment { get; set; }
}

Where userinformation, shift, subdepartment is a navigation properties ef core

I need build datagrid with dynamic columns (dates of month) and one static(first) column with name of user

Have a problem with building datagrid because not in every day user have an active schedule and monthes have ta diff count of days
So i cant build a grid classic way by static columns count and names of column

In the past i do this table in desktop winforms by row and column indexes/names with loop

For now i do this
List of schedules grouped by user id

<Columns>
    <RadzenDataGridColumn TItem="List<Schedule>" Width="160px" Title="username" Frozen=true Filterable=true>
        <Template Context="group">
            @group.First().ShiftUser.FullName
        </Template>
    </RadzenDataGridColumn>
    @foreach (var date in datesOfMonth)
    {
        <RadzenDataGridColumn TextAlign="TextAlign.Center" TItem="List<Schedule>" Width="40px" Title="@date.ToString("dd.MM")">
            <Template Context="group">
                @foreach (var schedule in group)
                {
                    if (schedule.Date == date)
                    {
                        <RadzenBadge Style="@($"background-color:{schedule.Shift.Color};color: {schedule.Shift.TextColor};")">
                           @schedule.Shift.Name
                        </RadzenBadge>
                    }
                }
            </Template>
        </RadzenDataGridColumn>
    }
</Columns>

But this example not filtering(any type of filter)
And i think in future ill have a problems with cell selection and getting schedule from a cell

Any ideas
Thx for any help
Respect

This demo might help you:

@enchev thx for fast and helpfull reply

I try and some parts of code work as expected
but i still have a problem((

problem in field Property of DataGrid column

i modify method GetColumnPropertyExpression and now it looks like this

public string GetColumnPropertyExpression(string name, Type type)
 {
     var expression = $@"it[""{name}""]";
     if (type == typeof(int))
     {
         return $"{expression} != null ? int.Parse({expression}.ToString()) : 0";
     }
     else if (type == typeof(UserInformation))
     {
         return "FullName";
     }
     else if (type == typeof(Schedule))
     {
         return "Shift.Name";
     }
     return $"{expression} != null ? {expression}.ToString() : string.Empty";
 }

in dev tools have error

blazor.web.js:1 [2024-07-13T11:31:16.413Z] Error: System.ArgumentNullException: Value cannot be null. (Parameter 'type')
at System.ArgumentNullException.Throw(String paramName)
at System.ArgumentNullException.ThrowIfNull(Object argument, String paramName)
at System.Linq.Expressions.Expression.Property(Expression expression, Type type, String propertyName)
at Radzen.PropertyAccess.Getter[TItem,TValue](String propertyName, Type type)
at Radzen.Blazor.RadzenDataGridColumn1.OnInitialized() at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() at Radzen.Blazor.RadzenDataGridColumn1.SetParametersAsync(ParameterView parameters)

The main purpose of making a filter (FilterMode="FilterMode.CheckBoxList")

  • in the column with UserInformation type filter by FullName field
  • in the column with the Scheedule type filter on the Shift.Name field (Where Shift is a related class)

two days of trying, but so far, so bad :cold_sweat: