Hi,
My grid has a checkbox column and I am attempting to gather all of the selected (checked) rows in my grid (SfGrid).
BTW all checkboxes are selected in all grids.
I know my grid object is populated as the Grid.CurrentViewData will return the visible rows in the grid.
I have tried the Grid.GetSelectedRecordsAsync and Grid.GetSelectedRowIndexesAsync methods but they return an empty list (0 records).
Returns all visible rows:
var rows= myGrids[gridkey].CurrentViewData as IEnumerable<object>;
Returns an empty collection:
var rows =await myGrids[gridkey].GetSelectedRecordsAsync();
Any advice you can give for getting the selected rows in my grid?
Thanks in advance.:-)
|
public async Task selected()
{
foreach (var gridkey in myGrids.Keys)
{
if(gridkey == "First")
{
var firstSelected = await myGrids[gridkey].GetSelectedRecordsAsync();
} else if (gridkey == "second")
{
var secondSelected = await myGrids[gridkey].GetSelectedRecordsAsync();
}
}
} |
|
|
Hi,
I am able to reproduce the issue with the example you provided. You are correct that the .GetSelectedRecordAsync returns the selected row.
However I understand now that what I am really after, is to grab all of the checked rows, not necessarily the "selected" rows.
There are lots of rows in my grids and my users will likely never physically click on each row to select it.
I noticed that in the example you sent, there wasn't a checkbox column, so I added one to this example in the attachment.
How do I grab all of the checked rows in the grid?
If that is not possible directly, one solution would be if I could bind the checkbox column in the grid the to the Selected property of the data object, then I could iterate the data object and check the related Selected property.
Any help in finding the "checked" value for each row would be great! :-)
Thanks so much for sending the example, that is very useful in checking the issue on my end and being able to show you what I mean. :-)
Attachment: DataGrid_With_Checkbox_49abffe7.zip
|
<SfButton OnClick="clicked" Content="Click"></SfButton>
<SfButton OnClick="selected" Content="Get Selected"></SfButton>
@foreach (var d in Data)
{
<SfGrid DataSource="@Orders" @ref="myGrids[d]" AllowTextWrap="true" AllowSorting ="false" AllowFiltering="false" AllowPaging="true" Width="100%" EnableAltRow="true">
<GridTextWrapSettings WrapMode="WrapMode.Content"></GridTextWrapSettings>
<GridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></GridSelectionSettings>
<GridEvents DataBound="DataBound" TValue="Order"></GridEvents>
<GridPageSettings PageSize=10></GridPageSettings>
<GridColumns>
<Template>
@{
var item = (context as Order);
<SfCheckBox Checked="item?.Selected"></SfCheckBox>
}
</Template>
</GridColumn>
. . .
</GridColumns>
</SfGrid>
}
@code {
public List<Order> Orders { get; set; }
public List<string> Data = new List<string>() { "First", "second" };
private Dictionary<string, SfGrid<Order>> myGrids = new Dictionary<string, SfGrid<Order>>();
. . .
public async Task selected()
{
foreach (var gridkey in myGrids.Keys)
{
if(gridkey == "First")
{
var firstSelected = await myGrids[gridkey].GetSelectedRecordsAsync();
} else if (gridkey == "second")
{
var secondSelected = await myGrids[gridkey].GetSelectedRecordsAsync();
}
}
}
List<double> SelectIndex { get; set; }
public async Task DataBound(object args)
{
foreach (var gridkey in myGrids.Keys)
{
if(gridkey == "First")
{
var Source = await myGrids[gridkey].GetCurrentViewRecords();
var IndexNum = 0;
SelectIndex = new List<double>();
foreach (var record in Source)
{
if (record.Selected)
{
SelectIndex.Add(IndexNum);
}
IndexNum++;
}
await myGrids[gridkey].SelectRows(SelectIndex.ToArray());
} else if (gridkey == "second")
{
var Source = await myGrids[gridkey].GetCurrentViewRecords();
. . .
await myGrids[gridkey].SelectRows(SelectIndex.ToArray());
}
}
}
. ..
public class Order
{
. . .
public bool Selected { get; set; } = true;
}
} |