Treat null value as blank/empty in grouping

Hi,

I have a grid where I want to group on a certain value (complex type). The value might not be present, i.e., null, which causes the grid to display "no data".

Is it possible to treat the complex type, e.g., "Team.Name" as Team="" if the team is null? Without having to create a ViewModel?

Thank you in advance.

3 Replies 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team January 25, 2021 01:30 PM UTC

Hi Michael,  

Greetings from Syncfusion support.  

Query: “Treat null value as blank/empty in grouping” 

We have analyzed your query and we are quite unclear about your requirement, so kindly share the following details to validate the reported query at our end.  

  1. Do you want to group the null values separately and display in Grid.
  2. Share the Grid code example.
  3. Share the details about your Grid datasource.
  4. Share more details about your query.
 
Above requested details will be helpful for us to validate the reported query at our end and provide solution as early as possible.   

Regards, 
Vignesh Natarajan  




Michael Østerberg January 27, 2021 08:44 AM UTC

Hi, I tried replicating the error in a demo project, but alas no luck :-)

It correctly display my missing (null) variable as "null" - See screesnhot.

Something else must be preventing my data from showing. I'll dig deeper. 

You can close this for now.

Re-create project:
@page "/"
@using Syncfusion.Blazor.Grids

<h3>Component</h3>

<SfGrid DataSource="@data" AllowSorting="true"  AllowGrouping="true">
    <GridGroupSettings Columns="@GroupedColumns" ShowDropArea="false">
        <CaptionTemplate>
            @{
                var item = (context as CaptionTemplateContext);
                <div>@item.Key</div>
            }
        </CaptionTemplate>
    </GridGroupSettings>
    <GridColumns>
        <GridColumn Field=@nameof(testdata.name) HeaderText="Name" Width="120"></GridColumn>
        <GridColumn Field=@nameof(testdata.field1) HeaderText="Field1" Width="120"></GridColumn>
        <GridColumn Field=@nameof(testdata.field2) HeaderText="Field2" Width="120"></GridColumn>
    </GridColumns>
</SfGrid>
@code {
    List<testdata> data { get; set; }
    //Syncfusion Grid
    public string[] GroupedColumns = new string[] { "field2" };
    public class testdata
    {
        public string name { get; set; }
        public string field1 { get; set; }
        public string field2 { get; set; }

    }

    protected override async Task OnInitializedAsync()
    {
        data = GetData();
    }

    private List<testdata> GetData()
    {
        var data = new List<testdata>();
        data.Add(new testdata { name = "row1", field1 = "field1", field2 = "field1" });
        data.Add(new testdata { name = "row2", field1 = "field1", field2 = "field2" });
        data.Add(new testdata { name = "row3", field1 = "field1" });
        data.Add(new testdata { name = "row4", field1 = "field2", field2 = "field4" });
        data.Add(new testdata { name = "row5", field1 = "field3", field2 = "field2" });
        data.Add(new testdata { name = "row6", field1 = "field3", field2 = "field2" });
        data.Add(new testdata { name = "row7", field1 = "field2", field2 = "field1" });
        return data;
    }
}

Attachment: null_value_ea18cd80.zip

Marked as answer

RS Renjith Singh Rajendran Syncfusion Team January 28, 2021 01:29 PM UTC

Hi Michael, 

Thanks for your update. 

Please get back to us if you need further assistance. 

Regards, 
Renjith R 


Loader.
Up arrow icon