You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an HX grid with pagination in it. I am loading the data only when needed. When the grid loads, I load the first page worth of data. When the next page is clicked, I load the next set of page set of data.
Now I have "multi select" enabled and I thoguht if I would keep the loaded results in memory plus having the selected rows in memory that would be enough to keep the state.
What I want is if you load up the grid and are on page 1, you select 3 rows, and then go to page 2 and then go back to page 1 those 3 rows should still be checked.
Right now when I do this, it is wiped out.
I can't share my code but I did something essentially like the following code.
Using SelectedDataItemsChanged, when a row is selected I store it in my State class what has the HashSet property
In Dataprovider. I have a dictionary that stores the GridDataProvider result. When I pull back page 1 I store it into this Dictionary, when a user comes back to page 1 I check to see if it exists in my dictonary and if it does then I return that if not I go to the database and grab that "new" page and then store it as well.
<HxGrid MultiSelectionEnabled="true" Responsive="true" SelectedDataItemsChanged="SelectedChanged" TItem="CultureInfo" DataProvider="ClientSideProcessingDataProvider" PageSize="10">
<Columns>
<HxGridColumn HeaderText="LCID" ItemTextSelector="@(item => item.LCID.ToString())" SortKeySelector="@(item => item.LCID)" IsDefaultSortColumn="true" />
<HxGridColumn HeaderText="DisplayName" ItemTextSelector="@(item => item.DisplayName)" SortKeySelector="@(item => item.DisplayName)" />
<HxGridColumn HeaderText="Name" ItemTextSelector="@(item => item.Name)" SortKeySelector="@(item => item.Name)" />
<HxGridColumn HeaderText="EnglishName" ItemTextSelector="@(item => item.EnglishName)" SortKeySelector="@(item => item.EnglishName)" />
</Columns>
</HxGrid>
<p>
Selected culture infos:
@foreach (var cultureInfo in selectedCultureInfos)
{
<span @key="@cultureInfo"> @cultureInfo.Name</span>
}
</p>
@code {
Dictionary<int, GridDataProviderResult<CultureInfo> MyProperty {get; set;}
private void SelectedChanged(HasSet<CultureInfo> selected){
// would call my state here and update the value
// it would do something like this StoredSelectedState.UnionWith(selected);
}
private Task<GridDataProviderResult<CultureInfo>> ClientSideProcessingDataProvider(GridDataProviderRequest<CultureInfo> request)
{
if(MyProperty.ContainsKey(request.StartIndex)){
return MyProperty[request.StartIndex]
}
else {
// call my serever and get data back
// store in Dictonary and call it back up if they go back to that page.
// return new GridDataProviderResult
}
}
}
I was hoping this would work as I am storing all the results into a Dictonary even as the GridDataProviderResult and storing all the selected rows. I am not making them "new" or anything so I thought they would be all the same reference.
Yet when I go back to the previous page non onf the selected rows are selected.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi
I have an HX grid with pagination in it. I am loading the data only when needed. When the grid loads, I load the first page worth of data. When the next page is clicked, I load the next set of page set of data.
Now I have "multi select" enabled and I thoguht if I would keep the loaded results in memory plus having the selected rows in memory that would be enough to keep the state.
What I want is if you load up the grid and are on page 1, you select 3 rows, and then go to page 2 and then go back to page 1 those 3 rows should still be checked.
Right now when I do this, it is wiped out.
I can't share my code but I did something essentially like the following code.
I was hoping this would work as I am storing all the results into a Dictonary even as the GridDataProviderResult and storing all the selected rows. I am not making them "new" or anything so I thought they would be all the same reference.
Yet when I go back to the previous page non onf the selected rows are selected.
I am not sure how to do this.
Beta Was this translation helpful? Give feedback.
All reactions