Hello.
I'm not very good at English, but I'll do my best to communicate.
Is there any way to select rows at NOT initial rendering?
For example, if it is already rendered grid, and select a condition and submit in an external form, the corresponding row(s) will be selected.
Regards,
Atsushi
|
await Grid.SelectRow(RowIndex); //RowIndex is double type
await Grid.SelectRow(RowIndexes); //RowIndexes is double[] type |
Hi Jeevakanth,
Thanks for the reply.
As you told me, the simple Selectrow(s) method worked correctly.
I hadn't noticed it either, but the situation where it didn't work was updating the DataSource just before.
I wrote a sample code based on the code in the following URL.
@page "/selectrow"
@using Syncfusion.Blazor.Grids<h3>SelectRowTest</h3><SfGrid @ref="@Grid" DataSource="@Orders" AllowFiltering="true" AllowPaging="true" Height="315">
<GridSelectionSettings Type="SelectionType.Multiple"></GridSelectionSettings> <GridColumns> <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Center" Width="120"></GridColumn> <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer ID" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Center" Width="150"></GridColumn> <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Center" Width="130"></GridColumn> <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Center" Width="120"></GridColumn> </GridColumns></SfGrid><label for="target-customer-id">Target customer ID</label>
<input type="text" id="target-customer-id" @bind="TargetCustomerID"/><button @onclick="ResetOrders">Reset Orders</button>@code{ SfGrid<Order> Grid;
public List<Order> Orders { get; set; } List<double> SelectIndex { get; set; } string TargetCustomerID = "ALFKI"; protected override void OnInitialized()
{ InitOrders(); } private void InitOrders()
{ Orders = Enumerable.Range(1, 12).Select(x => new Order() { OrderID = 1000 + x, CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)], Freight = 2.1 * x, OrderDate = DateTime.Now.AddDays(-x), }).ToList(); }
public async Task ResetOrders() { InitOrders(); var IndexNum = 0; SelectIndex = new List<double>(); foreach (var record in Orders) { if (record.CustomerID == TargetCustomerID) { SelectIndex.Add(IndexNum); } IndexNum++; } await Grid.SelectRows(SelectIndex.ToArray()); } public class Order
{ public int? OrderID { get; set; } public string CustomerID { get; set; } public DateTime? OrderDate { get; set; } public double? Freight { get; set; } }}What should I do if I want to update the DataSource and make the selection programmatically at the same time?
Thank you for any help you can provide.
|
<SfGrid @ref="@Grid" DataSource="@Orders" AllowFiltering="true" AllowPaging="true" Height="315">
<GridSelectionSettings Type="SelectionType.Multiple"></GridSelectionSettings>
<GridEvents TValue="Order" DataBound="DataBoundHandler"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Center" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer ID" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Center" Width="150"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Center" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Center" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
<label for="target-customer-id">Target customer ID</label>
<input type="text" id="target-customer-id" @bind="TargetCustomerID" />
<button @onclick="ResetOrders">Reset Orders</button>
@code{
SfGrid<Order> Grid;
public List<Order> Orders { get; set; }
List<double> SelectIndex { get; set; }
string TargetCustomerID = "ALFKI";
bool SelectRows = false;
protected override void OnInitialized()
{
InitOrders();
}
private void InitOrders()
{
Orders = Enumerable.Range(1, 12).Select(x => new Order()
{
OrderID = 1000 + x,
CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],
Freight = 2.1 * x,
OrderDate = DateTime.Now.AddDays(-x),
}).ToList();
}
public async Task ResetOrders()
{
InitOrders();
SelectRows = true;
}
public async Task DataBoundHandler()
{
if (SelectRows)
{
SelectRows = false;
var IndexNum = 0;
SelectIndex = new List<double>();
foreach (var record in Orders)
{
if (record.CustomerID == TargetCustomerID)
{
SelectIndex.Add(IndexNum);
}
IndexNum++;
}
await Grid.SelectRows(SelectIndex.ToArray());
}
}
public class Order
{
public int? OrderID { get; set; }
public string CustomerID { get; set; }
public DateTime? OrderDate { get; set; }
public double? Freight { get; set; }
}
} |
Hi Jeevakanth,
I did as you taught me and it worked perfectly.
I'll be using DataBound from now on.
Thank you for your support.
Atsushi.