Selecting rows through checkbox column

Hi, i have this col:

on databound:

Image_2514_1703043896514


and i have this issue

1: wrong the colour gray in unselected rows, can i fix it?

Image_2053_1703043858107

2: i need only checkbox rows true, not all:

Image_1135_1703043982505


1 Reply 1 reply marked as answer

SP Sarveswaran Palani Syncfusion Team December 22, 2023 04:37 AM UTC

Hi Sergio,

Greetings from Syncfusion support.

From your query, we suspect that you’re removing the checkbox for some rows by using class in RowDataBound event. We would like to inform you that, by doing so, it only removes the checkbox in UI part not in back end. So that, you have getting total count instead of selected rows. To overcome the reported issue, we have prepared sample to restrict the selection of specific records by using RowSelecting event when the “SelectAll” check box is clicked. Kindly refer the attached code snippet and sample for your reference.

<SfGrid DataSource="@Orders" @ref="Grid" TValue="Order" AllowSelection="true" AllowPaging="true">

    <GridPageSettings PageSize="100"></GridPageSettings>

    <GridSelectionSettings CheckboxOnly="true" Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></GridSelectionSettings>

    <GridEvents RowSelecting="RowSelectingHandler" TValue="Order"></GridEvents>

    <GridColumns>

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

        .

        .

    </GridColumns>

</SfGrid>

@code {

    public async Task RowSelectingHandler(RowSelectingEventArgs<Order> args)

    {

        if (args.IsHeaderCheckboxClicked && !flag) //if header checkbox clicked

        {

            flag = true;

            args.Cancel = true;

            var len = args.RowIndexes.Count;

            for (int i = 0; i < len; i++)

            {

                if ((args.Datas[i].OrderID) > 1003)

                {

                    var value = args.Datas[i].OrderID;

                    var rowIndex = Grid.GetRowIndexByPrimaryKeyAsync(value);

                    int rvalue = Convert.ToInt32(rowIndex.Result);

                    RowIndexs.Add(rvalue); //add row index to list

                }

            }

            await Grid.SelectRowsAsync(RowIndexs.ToArray());//  select rows

            flag = false; //reset flag

        }

    }

}


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

Reference: https://blazor.syncfusion.com/documentation/datagrid/events#rowselecting

If you have any further queries, please get back to us.

Regards,
Sarvesh


Marked as answer
Loader.
Up arrow icon