问题
Greetings,
I have a DataGrid showing a PagedCollectionView which has the total amount of records included.
In total we have about 4220 records, with 20 records showing per page we have about 210 pages.
Now I've been trying to implement this:
When I search for a person I want to have this person show on top of the page AND have the page set to anything that is near the page it would be on.
I managed to get the person on top using the example given in Linq Get items higher then lastname however the PagedCollectionview gets overwriten by these results. Since this skips everything before the wanted person the amount of pages differs.
So basicly what I want is to have a searchfield where I can enter "Jan". And then I want the page to jump to the page where Jan could be (+/- 1 page lower or higher) and have "Jan" as first record.
回答1:
Found my own answer.
Not in a very nice way but, since at all times firstly the total amount of members is being loaded, I created a check to see if the currently loaded amount is higher then the total amount first loaded.
Like:
if (loadOperation.TotalEntityCount >= itemCount || !string.IsNullOrEmpty(FilterText))
{
this.ItemCount = loadOperation.TotalEntityCount;
}
else
{
if (!DeleteMember)
{
pageIndex = (int)((this.ItemCount - loadOperation.TotalEntityCount) / this.PageSize);
RaisePropertyChanged("PageIndex");
}
else
{
DeleteMember = false;
itemCount -= 1;
}
}
The delete member is to make sure it doesn't try to set the page index when a member is deleted and thus TotalEntityCount would be 1 lower then itemcount.
来源:https://stackoverflow.com/questions/4737233/getting-to-certain-member-using-datapager-and-datagrid