我有一个Telerik网格,它需要按钮来选择First、Last、Previous和Next记录。到目前为止,我有以下方法,但都选择最后一行:
private void GoToFirstRow(){
var firstRecord = GridDataSource.FirstOrDefault();
var collectionOfFirstRecord = GridDataSource.Where(x => x.ID == firstRecord.ID);
SelectedItems = new List<ReportRO>(collectionOfFirstRecord);
}
private void GoToLastRow(){
var lastRecord = GridDataSource.LastOrDefault();
var collectionOfLastRecord = GridDataSource.Where(x => x.ID == lastRecord.ID);
SelectedItems = new List<ReportRO>(collectionOfLastRecord);
}
private void GoToPreviousRow(){
int prevIndex = index - 1;
var prevRecord = GridDataSource.ElementAt(prevIndex);
var collectionOfPrevRecord = GridDataSource.Where(x => x.ID == prevRecord.ID);
SelectedItems = new List<ReportRO>(collectionOfPrevRecord);
}
我想也许是"OrDefault"部分在GoToFirstRow是问题,所以我切换了"首先,"但它没有帮助。
为了彻底起见,以下是我的网格和相关元素:
<TelerikGrid Data="@GridDataSource"
EditMode="@Telerik.Blazor.GridEditMode.Incell"
@ref="Grid"
SelectionMode="Telerik.Blazor.GridSelectionMode.Single"
@bind-SelectedItems="@SelectedItems">
@code {
[Parameter]
public ReportCollection GridDataSource { get; set; }
public TelerikGrid<ReportRO> Grid;
public IEnumerable<ReportRO> SelectedItems { get; set; } = Enumerable.Empty<ReportRO>();
我没有给我的虚拟记录添加id。由于它们都是相同的id,并且我将方法绑定到记录id,因此没有"first";记录。