Selecting a row in a grid


 I am trying to select the data from a grid row based on AspNetUser to assign Roles to a selected user. 

Currently l am using userData : private List<UserModel> userData = null;

The application crashes with an exception after compiling. The second try the compiler finds errors: 

Severity Code Description Project File Line Suppression State 

Error (active) CS0029 Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List

 which is the beginning of the Task. 

 Changing "userData" To "UserModel results" in a compiler error: 

 Severity Code Description Project File Line Suppression State

 Error CS0029 Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List

 Please advice what would be the correct Parameter for TValue="" and private async Task SelectedRow(RowSelectEventArgs args) 

The rest of the code inside the Task is copied from the Syncfusion Demo


<SfGrid @ref="SfUserGrid" DataSource="userData" AllowFiltering="true" AllowGrouping="true" AllowPaging="true" AllowPdfExport="true" AllowExcelExport="true" AllowSorting="true" AllowSelection="true"

                                Toolbar="@toolbar">

                                <GridEditSettings Mode="EditMode.Dialog" AllowAdding="true" AllowEditing="true" AllowDeleting="true" >

                                    <HeaderTemplate>

                                        <span>@(GetDialogHeaderText(context as UserModel))</span>

                                    </HeaderTemplate>


                                    <FooterTemplate>

                                        <SfButton OnClick="@Save" IsPrimary="true">@DialogButtonCaption</SfButton>

                                        <SfButton OnClick="@Cancel">Cancel</SfButton>

                                    </FooterTemplate>

                                </GridEditSettings>

                                <GridPageSettings PageSize="5"></GridPageSettings>

                                <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Menu"></GridFilterSettings>

                                <GridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Single"></GridSelectionSettings>

                                <GridEvents RowSelected="SelectedRow" TValue="UserModel"></GridEvents>

                                <GridColumns>

                                    <GridColumn HeaderText="User Name" Field="@nameof(UserModel.UserName)" Width="220px"></GridColumn>

                                    <GridColumn HeaderText="Email Address" Field="@nameof(UserModel.Email)" Width="220px"></GridColumn>

                                    <GridColumn HeaderText="Email Confirmed" Field="@nameof(UserModel.EmailConfirmed)" Width="100px"></GridColumn>

                                    <GridColumn HeaderText="Phone Number" Field="@nameof(UserModel.PhoneNumber)" Width="220px"></GridColumn>

                                    <GridColumn HeaderText="Phone Confirmed" Field="@nameof(UserModel.PhoneNumberConfirmed)" Width="100px"></GridColumn>

                                    <GridColumn HeaderText="2 Factor Enabled" Field="@nameof(UserModel.TwoFactorEnabled)" Width="100px"></GridColumn>

                                    <GridColumn HeaderText="Access Failed" Field="@nameof(UserModel.AccessFailedCount)" Width="100px"></GridColumn>

                                </GridColumns>


                                <SfSpinner @bind-Visible="@VisibleProp"></SfSpinner>

                            </SfGrid>

@code {

    private SfGrid<UserModel>? SfUserGrid { get; set; }

private List<UserModel> userData = null;

    private string DialogButtonCaption { get; set; }

    private bool VisibleProp { get; set; } = false;

    [Parameter]

    public string Selection { get; set; }

:

:

    private async Task SelectedRow(RowSelectEventArgs<UserModel> args)

    {

        SelectedRowIndexes = await this.SfUserGrid.GetSelectedRowIndexes();

        TotalValue = SelectedRowIndexes.ToArray();


        Selection = "";

        foreach (var data in TotalValue)

        {

            Selection = Selection + " " + data.ToString();

        }

        StateHasChanged();

    }

}


3 Replies 1 reply marked as answer

NP Naveen Palanivel Syncfusion Team May 31, 2023 01:06 PM UTC

Hi Uwe,

We have reviewed your request and would like to inform you that we are able to retrieve the data and index of the selected row from the event args. To assist you further, we have attached a simple sample in this ticket for your reference

If it does not meet your requirement then kindly share the below details to validate further at our end.


  1. Share us the entire Grid code snippet along with model class
  2. Could you share the details of your exact requirement and what you want to achieve in the RowSelected event.
  3. Share us the video demonstration of the issue .
  4. If possible share us an simple issue reproduceable sample or try to modify the above mentioned sample.


The above-requested details will be very helpful for us to validate the reported query at our end and provide the solution as early as possible


Regards,

Naveen Palanivel


Attachment: Blazor_Selection_5eb40677.zip


UJ Uwe Jädick May 31, 2023 01:13 PM UTC

Hello Naveen,

Thank you for getting beack to me on this topic. It seems that the demo I found is not working at all. Hence, I had to find a better solution.

I changed the RowSelected event and not using  SelectedRowIndexes = await this.SfUserGrid.GetSelectedRowIndexes(); anymore. Instead I am using var Selected = args.UserName to display the selected user. This is currently working.

The next issue I have is with Microsoft Identity Management and not Syncfusion anymore.


Best Regards

Uwe


Marked as answer

NP Naveen Palanivel Syncfusion Team June 1, 2023 01:44 PM UTC

Hi Uwe,

Thank you for updating the status of the issue. If you require any further assistance, please don't hesitate to reach out to us.


Regards,

Naveen Palanivel


Loader.
Up arrow icon