No records to display when sorting specific column in DataGrid

When using a datagrid, I get a "No records to display" message when sorting specific columns.

The grid consists of several (variable numer) of columns that are properties of a class, together with two columns that are properties of a related class.

When sorting either of the two columns of the related class, the "No records to display" message is shown. When sorting either of the other columns, records are displayed.


Is there something wrong with my approach?
Any help would be greatly appreciated.

----------------------------------------------------------------------------------------


<SfGrid ID="Grid" @ref="ResultGrids"
    TValue="ExperimentResult"
    DataSource="@experimentResults"
    AllowPaging="true"
    AllowSorting="true"
    AllowSelection="true"
    Toolbar="@(new List<string>() { "ExcelExport" })"
    AllowExcelExport="true">
    <GridEvents OnToolbarClick="ToolbarClickHandler" TValue="ExperimentResult"></GridEvents>
    <GridSelectionSettings AllowDragSelection="true" Mode="Syncfusion.Blazor.Grids.SelectionMode.Row" Type="SelectionType.Multiple"></GridSelectionSettings>
    <GridPageSettings PageSize="20"></GridPageSettings>
    <GridSortSettings>
        <GridSortColumns>
            <GridSortColumn Field="@nameof(ExperimentResult.Experiment.LocalTime)" Direction="SortDirection.Descending"></GridSortColumn>
        </GridSortColumns>
    </GridSortSettings>
    <GridColumns>
        <GridColumn Field=@nameof(ExperimentResult.Experiment.LocalTime)
                HeaderText="Date and time"
                Format="dd-MM-yyyy HH:mm:ss"
                TextAlign="TextAlign.Right"
                Width="80">
            <Template Context="experimentContext">
                @{
                    var experimentResult = (experimentContext as ExperimentResult);
                    @experimentResult.Experiment.LocalTime
                    ;
                }
            </Template>
        </GridColumn>
        <GridColumn Field=@nameof(ExperimentResult.Experiment.SampleType)
                HeaderText="Sample source"
                Width="60">
            <Template Context="experimentContext">
                @{
                    var experimentResult = (experimentContext as ExperimentResult);
                    @experimentResult.Experiment.SampleType
                    ;
                }
            </Template>
        </GridColumn>


        @foreach (var name in columnNames)
        {
            <GridColumn Field="@name.Key" IsPrimaryKey="@(name.Key == "ExperimentId")" AutoFit="true">
                <GridColumns>


                    @foreach (var elementName in name)
                    {
                        <GridColumn Field="@elementName.Name" IsPrimaryKey="@(elementName.Name == "ExperimentId")"
                        Format="n2"
                        Width="10%"
                        AutoFit="true">
                            <Template Context="columnContext">
                                @{
                                    var experimentResult = (columnContext as ExperimentResult);
                                    double? concentration = experimentResult.IonList?.Where(ion => ion.Name == elementName.Name).FirstOrDefault()?.Concentration;
                                    if (concentration != null)
                                    {
                                        @double.Round((double)concentration, 2)
                                        ;
                                    }




                                }
                            </Template>
                        </GridColumn>
                    }
                </GridColumns>
            </GridColumn>
        }
    </GridColumns>


</SfGrid>


Attachment: 20230523_Syncfusion_Example_d41f7999.zip


2 Replies

JB Jan Brouwer May 24, 2023 11:07 AM UTC

I might've found the problem.
Using "@nameof()" does not seem to work for the columns that refer to properties of the related class.



NP Naveen Palanivel Syncfusion Team May 26, 2023 02:58 PM UTC

Hi Jan,
After reviewing your query, we have identified the problem you are facing when sorting the complex column. Upon validating the provided code, we discovered that the complex column field is defined incorrectly, leading to the root cause of the problem. This is why no records are being displayed when sorting the complex column. To help you further, we suggest referring to the code snippet and sample provided below, which offer more information on how to resolve this issue.


    <GridSortSettings>

        <GridSortColumns>

            <GridSortColumn Field="Name.FirstName" Direction="SortDirection.Descending"></GridSortColumn>

         

        </GridSortColumns>

    </GridSortSettings>

    <GridColumns>

        <GridColumn Field=@nameof(EmployeeData.EmployeeID) HeaderText="EmployeeID" TextAlign="TextAlign.Right" Width="120"></GridColumn>

        @*<GridColumn Field=@nameof(EmployeeData.Name.FirstName) HeaderText="First Name" Width="150"></GridColumn>*@

        <GridColumn Field="Name.FirstName" HeaderText="First Name" Width="150"></GridColumn>

        @*  <GridColumn Field=@nameof(EmployeeData.Name.LastName) HeaderText="Last Name" Width="130"></GridColumn>*@

        <GridColumn Field="Name.LastName" HeaderText="Last Name" Width="130"></GridColumn>




Please let us know if you have any concerns.


Regards,

Naveen Palanivel


Attachment: Blazor_Complex_15f5e0c5.zip

Loader.
Up arrow icon