<SfGrid @ref="GridWorkSpaces" DataSource="@WorkSpaces" AllowPaging="false">
<GridSelectionSettings EnableSimpleMultiRowSelection="true" Mode="SelectionMode.Row" CheckboxOnly="true" PersistSelection="true" Type="SelectionType.Multiple"></GridSelectionSettings>
<GridColumns>
<GridColumn Field=@nameof(WorkSpaceInfoDto.Id) IsPrimaryKey="true" Visible="false" HeaderText="Id" TextAlign="TextAlign.Left"></GridColumn>
<GridColumn Type="ColumnType.CheckBox" AllowFiltering="false" AllowSorting="false" Width="60"></GridColumn>
<GridColumn Field=@nameof(WorkSpaceInfoDto.Name) HeaderText="Espacio de Trabajo" TextAlign="TextAlign.Left"></GridColumn>
<GridColumn HeaderText="Perfil" TextAlign="TextAlign.Left">
<Template>
@{
if (context is WorkSpaceInfoDto item)
{
var profiles = item.Profiles;
<SfDropDownList TItem="BasicProfileInfoDto" TValue="string" PopupHeight="230px" Placeholder="Seleccione un perfil"
DataSource="@profiles">
<DropDownListEvents TValue="string"></DropDownListEvents>
<DropDownListFieldSettings Text="Name" Value="Id"></DropDownListFieldSettings>
</SfDropDownList>
}
}
</Template>
</GridColumn>
<GridColumn HeaderText="Role" TextAlign="TextAlign.Left">
<Template>
@{
if (context is WorkSpaceInfoDto item)
{
var roles = item.Roles;
<SfDropDownList TItem="RoleInfoDto" TValue="string" PopupHeight="230px" Placeholder="Seleccione un rol"
DataSource="@roles">
<DropDownListEvents TValue="string"></DropDownListEvents>
<DropDownListFieldSettings Text="Name" Value="Id"></DropDownListFieldSettings>
</SfDropDownList>
}
}
</Template>
</GridColumn>
</GridColumns>
</SfGrid>
on the csharp I have the following:
var selectedRows = await GridWorkSpaces.GetSelectedRecords();
foreach (var item in selectedRows)
{
await JsRuntime.InvokeAsync<object>("console.log", $"Data Row: {JsonConvert.SerializeObject(item)}");
}
on the foreach loop, i need to access the selected values of the dropdownlist, but i cannot find how
Any idea? thanks
. . .
<SfGrid AllowPaging="true" DataSource="@GridData" AllowSelection="true" ShowColumnChooser="true" Toolbar="@(new List<string>() { "Add","Edit","Delete","Update","Cancel" })">
<GridEvents TValue="OrdersDetails" RowSelected="RowSelectHandler"></GridEvents>
. . .
<GridColumns>
<GridColumn Type="ColumnType.CheckBox" Width="60"></GridColumn>
. . .
<Template>
<SfDropDownList ID="ShipCountry" Value="@((context as OrdersDetails).ShipCountry)" TItem="OrdersDetails" TValue="string" DataSource="@GridData">
<DropDownListEvents TValue="string" OnValueSelect="OnSelect" ValueChange="ValueChange"></DropDownListEvents>
<DropDownListFieldSettings Text="ShipCountry" Value="ShipCountry"></DropDownListFieldSettings>
</SfDropDownList>
</Template>
</GridColumn>
<GridColumn Field=@nameof(OrdersDetails.ShipState) HeaderText=" ShipState" EditType="EditType.DropDownEdit" Width="150">
<Template>
<SfDropDownList ID="ShipState" Value="@((context as OrdersDetails).ShipState)" Placeholder="Select a State" TItem="OrdersDetails" TValue="string" DataSource="@GridData">
<DropDownListEvents TValue="string" OnValueSelect="OnSelect" ValueChange="ValueChange"></DropDownListEvents>
<DropDownListFieldSettings Text="ShipState" Value="ShipState"></DropDownListFieldSettings>
</SfDropDownList>
</Template>
</GridColumn>
</GridColumns>
</SfGrid>
@code{
public List<OrdersDetails> GridData { get; set; }
. . .
public void RowSelectHandler(RowSelectEventArgs<OrdersDetails> args)
{
// Here you can customize your code
}
public void OnSelect(SelectEventArgs args)
{
}
public void ValueChange(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string> args)
{
// you can get changed value in args.Value
}
} |
<SfButton OnClick="Clicked" Content="Click Here"></SfButton>
<SfGrid @ref="GridWorkSpaces" AllowPaging="true" DataSource="@GridData" AllowSelection="true" ShowColumnChooser="true" Toolbar="@(new List<string>() { "Add","Edit","Delete","Update","Cancel" })">
. .. .. . . . . .
</SfGrid>
@code{
SfGrid<OrdersDetails> GridWorkSpaces { get; set; }
public string DropSelected { get; set; }
public List<OrdersDetails> GridData { get; set; }
. . . .. . . . . . .
public void ValueChange(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string> args)
{
DropSelected = args.Value;
}
public async Task Clicked()
{
var selectedRows = await GridWorkSpaces.GetSelectedRecords();
foreach (var item in selectedRows)
{
var t = DropSelected; // here you can get the selected value of the dropdownlist
}
}
}
|
<SfGrid AllowPaging="true" DataSource="@GridData" ...>
...
<GridColumns>
...
<GridColumn Field=@nameof(OrdersDetails.ShipCountry) HeaderText="Ship Country" EditType="EditType.DropDownEdit" Width="150">
<Template>
<SfDropDownList ID="ShipCountry" Value="@((context as OrdersDetails).ShipCountry)" TItem="OrdersDetails" TValue="string" DataSource="@GridData">
<DropDownListEvents TValue="string" OnValueSelect="OnSelect" ValueChange="ValueChange"></DropDownListEvents>
<DropDownListFieldSettings Text="ShipCountry" Value="ShipCountry"></DropDownListFieldSettings>
</SfDropDownList>
</Template>
</GridColumn>
<GridColumn Field=@nameof(OrdersDetails.ShipState) HeaderText=" ShipState" EditType="EditType.DropDownEdit" Width="150">
<Template>
<SfDropDownList ID="ShipState" Value="@((context as OrdersDetails).ShipState)" Placeholder="Select a State" TItem="OrdersDetails" TValue="string" DataSource="@GridData">
<DropDownListEvents TValue="string" OnValueSelect="OnSelect" ValueChange="ValueChange"></DropDownListEvents>
<DropDownListFieldSettings Text="ShipState" Value="ShipState"></DropDownListFieldSettings>
</SfDropDownList>
</Template>
</GridColumn>
</GridColumns>
</SfGrid>
@code{
public List<OrdersDetails> GridData { get; set; }
public string ShipStateDropSelected { get; set; }
public string ShipCountryDropSelected { get; set; }
...
public void ValueChange(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string> args)
{
if(args.Element.ID == "ShipState")
{
ShipStateDropSelected = args.Value; //Assign value to ShipStateDropSelected when ShipState column dropdown value selected
}
else if(args.Element.ID == "ShipCountry")
{
ShipCountryDropSelected = args.Value; //Assign value to ShipCountryDropSelected when ShipCountry column dropdown value selected
}
}
}
|