Hello,
I get the data by Custom Adaptor. The controller is creating the content with entiy framework and doing the filtering, sorting and paging. The treegrid is bind with self-referential uuid. Paging is enabled!
I want to reselect the last selected row after I reenter the page - the last selected uuid is stored in the adaptor as a service - this is already working.
But the problem is to select the row by the ID (uuid) or index (and the page!). Page and index can be "calculated" client- or server-side...
How can I select the correct row? The problem is, that the index in the flat list is not the correct index in the treegrid.
Can you help me please?
|
<SfButton OnClick="SelectRow" Content="Navigate"></SfButton>
<SfTreeGrid @ref="treeGrid" TValue="TreeData.BusinessObject" AllowPaging="true"
HasChildMapping="isParent" IdMapping="TaskId" ParentIdMapping="ParentId"
TreeColumnIndex="1" AllowSorting="true"
>
<SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
<TreeGridPageSettings PageSize="2"></TreeGridPageSettings>
……
private async Task SelectRow()
{
var inx =await TreeGrid.GetRowIndexByPrimaryKeyAsync(7);//get the index value
await TreeGrid.SelectRowAsync(inx);
}
} |
I tested your code with button and calling in DataBound event.
Both time the calculated index is -1 (I am using UUID (string) as primary key).
And how treegrid selecting is working with paging as treegrid with custom adaptor is just working with PageSizeMode = Root? How the page can be calculated without knowing how many rows has a page?
I added a breakpoint in the Select() method:
The adaptor result:
In the treeGrid.FlatData property the row is available, too:
Maybe something in the control configuration is wrong defined:
|
<SfTreeGrid @ref="treeGrid" TValue="TreeData.BusinessObject" AllowPaging="true"
HasChildMapping="isParent" IdMapping="TaskId" ParentIdMapping="ParentId"
TreeColumnIndex="1" AllowSorting="true"
>
<SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
<TreeGridPageSettings PageSizeMode="PageSizeMode.Root"></TreeGridPageSettings>
<TreeGridColumns>
<TreeGridColumn Field="TaskId" HeaderText="Task ID" Width="80" TextAlign="TextAlign.Right"></TreeGridColumn>
<TreeGridColumn Field="Uuid" HeaderText="UUId" IsPrimaryKey="true" Width="100"></TreeGridColumn>
</TreeGridColumns>
</SfTreeGrid>public async Task DataHandler()
{
var inx =await treeGrid?.GetRowIndexByPrimaryKey("dsdadsafe-32fedt-fd34-df3gsad");//pass the primary key value
await treeGrid?.SelectRow(inx);
} |
Hi,
yes, you are right! I thought that the IdMapping definition is enough!
With adding the ID column with attribute isPrimaryKey the selection is now working!
Nice - thx very much!
But can you tell me how I get the page of the item with the searched ID? Calculating with the page size is not working because of PageSizeMode is Root!
|
<SfTreeGrid @ref="treeGrid" TValue="TreeData.BusinessObject" AllowPaging="true"
HasChildMapping="isParent" IdMapping="TaskId" ParentIdMapping="ParentId"
TreeColumnIndex="1" AllowSorting="true"
>
……
</SfTreeGrid>public async Task DataHandler()
{
var dat = TreeData.GetSelfDataSource().ToList();
for (var i = 0; i < 15; i++)
{
if (dat[i].ParentId == null){
parentData.Add(dat[i]); // filter the parent records
}
}
var val = parentData.FindIndex(x => x.TaskId == searchval[0].ParentId); // filter the parent index from serched record
if (val >= 0 || val <= 11)
{
//the record in page 1
}
else if(val == 12 || val == 23)
{
// the record in page 2
}
}public override object Read(DataManagerRequest dm, string key = null)
{
filterCount = null;
IEnumerable<TreeData.BusinessObject> DataSource = TreeGridData;
if (dm.Search != null && dm.Search.Count > 0)
{
// Searching
DataSource = DataOperations.PerformSearching(DataSource, dm.Search);
searchval = DataSource.ToList();
}
if (dm.Sorted != null && dm.Sorted.Count > 0)
{
// Sorting
DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);
} |
thx for your proposal!
I have already solved it with calculating the page similar your hint:
I take all the roots, getting the root of the selected item I want to select and divide with the root page size (dm.Take value). Selecting this page and then GetRowIndexByPrimaryKey and SelectRowAsync(index)