Is it possible for an unbound checkbox to start checked ?

There is an unbound checkbox column in the grid. I would like to know if it is possible to have it initialized as checked. I notice that there is a DefaultValue parameter but what is the value that should be placed on it ? I tried  DefaultValue="true" but it didn't work.


<GridColumns>

<GridColumn HeaderText="" Type="ColumnType.CheckBox"    DefaultValue="?" />

......


1 Reply 1 reply marked as answer

PS Prathap Senthil Syncfusion Team July 28, 2023 12:46 PM UTC

Hi Ben,

Yes, it is possible to initialize an unbound checkbox in a grid as checked by default. For your specific requirement, we suggest using the select a row at the initial rendering feature and setting the 'SelectedRowIndex' value. We have already documented this topic, and we kindly advise you to refer to the following User Guide and sample for your reference.

<SfGrid DataSource="@Orders" AllowSelection="true" AllowPaging="true" SelectedRowIndex="0">

    <GridSelectionSettings CheckboxMode="CheckboxSelectionType.ResetOnRowClick" Type="SelectionType.Multiple"></GridSelectionSettings>

    <GridColumns>

        <GridColumn Type="ColumnType.CheckBox" DefaultValue="0" Width="50"></GridColumn>

        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>

        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>

        <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>

        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>

    </GridColumns>

</SfGrid>


Sample Link: https://blazorplayground.syncfusion.com/embed/rNhANQrlfhfftqwJ?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5


Documentation:
https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_SelectedRowIndex

https://blazor.syncfusion.com/documentation/datagrid/selection#select-row-at-initial-rendering

Regards,

Prathap S


Marked as answer
Loader.
Up arrow icon