DataGrid - GetPersistData and SetPersistData

Hello

I have been playing with the GetPersistData and SetPersistData in the DataGrid. I would like to store the persist data in our database so that I can re-apply when the user re-opens the grid. I have some questions:

1.Documentation.  

I cannot find any. I know there is some for Pivot Tables.  I have established that the persist data handles   

Search - yes (Syncfusion built in search on toolbar)
Column sort
Column width
Columns chosen
Grouping, although I have not tested this
Column Filters

Is there any doco?

2. Column Filters 

I have only tested Syncfusion.Blazor.Grids.FilterType.FilterBar and Syncfusion.Blazor.Grids.FilterType.Menu but note that it works in that the filter term is stored on GetPersistData and records are then correctly filtered on SetPersistData. However the filter term itself is not written back to the filter bar on SetPersistData, so there is no indication that the grid is filtered. Pretty sure this is a bug?

3. Column Filters when a FilterTemplate is used

Does not work when a FilterTemplate is used.  I guess this is probably a limitation? (fair enough).

4. Event to call GetPersistData

If I want to store the state of the grid when the user leaves the page, my initial thought was to call GetPersistData on the Dispose() method of the page. However, GetPersistData is async and cannot be called from Dispose().  Can you suggest an event?  Ideally (I think) I want something that fires any time a filter, sort, search etc action is undertaken by the user?


Many Thanks


9 Replies 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team September 1, 2020 02:18 PM UTC

Hi Richard, 

Greetings from Syncfusion support. 
 
Query 1 : 1.Documentation.  I cannot find any.Is there any doco? 
We have documented the State Management topic in our UG documentation section. Please refer the below documentation for more details. 

Query 2 : 2. Column Filters .However the filter term itself is not written back to the filter bar on SetPersistData, 
We tried to reproduce the reported problem by creating a sample. But we are not able to face the reported problem, on calling SetPersistData the FilterBar gets populated with the filtered text. We have prepared a video demo to show this behavior. Please download the video demo and sample for your reference. We have use the codes from above documentation to prepare the below sample. 
 
If you are still facing difficulties, then we need more details to further proceed on this and provide you a solution as early as possible. Kindly get back to us with the following details for better assistance.  
  1. Share the video demo showing the problem you are facing.
  2. Share with us the exact scenario you are facing the reported problem.
  3. Share the code details regarding how you are calling the SetPersistData method.

Query 3 : Column Filters when a FilterTemplate is used 
We are currently checking this scenario from our side. In the meantime could you please share with us the following details, which could be helpful for us to proceed further, 
  1. Share the FilterTemplate codes, and the custom filtering codes you are using.
  2. Share the video demo showing the problem you are facing when using FilterTemplate in Grid.
  3. Share the complete Grid codes.

Query 4 : 4. Event to call GetPersistData If I want to store the state of the grid when the user leaves the page, 
We have Destroyed event in Grid. We suggest you to use this event to get the persist data before leaving the page. Please refer the documentation link below, 

Please refer the codes below, 

 
<GridEvents Destroyed="Destroyed" TValue="Order"></GridEvents> 

public async Task Destroyed(){    _state = await Grid.GetPersistData();}

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



DI Ditchford September 2, 2020 09:40 AM UTC

Hello Renjith

Thanks for the feedback.  I have modified and attached your sample project to demonstrate the problems I am having as requested.  Details of how to recreate the issues are as below


Query 1 (above) > Thank you

Query 2 (above) > Goto Page Persist 01 > Type "Task 41" in Task filter field and hit enter > Press Save Persist > Clear filter term from Task field and hit enter > Press Apply Persists > the filter works, but the filter field is not populated

Query 2.1 (new) > Goto Page Persist 01 > Change size of Description column > Press Reset Persist > fails to reset (problem with this column only)

Query 3 (above) > Goto Page Persist 01 > Click on the Transaction Date Filter and set a date range > Save Persists > change the date range filter > Apply Persist > Filter is not reset (as noted I understand if this is a limitation)

Query 4 (above):

The following is all demonstrated on Page Persist 02

As you suggest I am using the Destroyed Event to capture the persist data.  I then reload this persist data when the page is opened again.  I used the Grid Created Event for this. The problem is (I think) that the data is not always properly captured during the Destroyed Event leading to an error on the subsequent Created event. To demonstrate this please do the following:

- Go to Persists 02 page (you will see a notification that the persist data has been applied)
- Go back to the home page (you will see a notification that the persist data has been saved)
- Go back to Page 02 and sometimes you will get an error (see screen shot below)

Note you will not always get this error.  If you do not see the error then please stop the project, restart and try again.  I can create this error reasonably reliably.

So I think the problem is in saving the persist data in the Destroyed event when leaving the page. When this does work it seems to work for all (sort, search, column chooser, column width, column position).  It does not work for filtering however.  

I have tried using the ActionComplete event instead of the Destroyed event to store persist data after every change by the user. You will see it commented out in the code. But this too has problems:

- Again the filtering is not persisted
- A column size change is not captured by this event.  I tried using ResizeStopped event to handle this, but this is too chatty / does not capture persist data correctly




My preference is to use the Destroyed event if it can be made reliable (it seems like the right place to capture the data) and the issue with the not capturing filtering can be resolved.

Many thanks

Looking forward to hearing from you.

Attachment: BlazorApp1_f8ec512.zip


RS Renjith Singh Rajendran Syncfusion Team September 4, 2020 02:08 PM UTC

Hi Richard, 

Thanks for sharing the details. 

Query 2 : the filter works, but the filter field is not populated 
We have confirmed it as a bug and logged the defect report “Key value in FilterBar cell not persist when calling SetPersistData when using GridFilterSettings in Grid. Thank you for taking time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle) and including the defect fix in our upcoming  bi-weekly release which is expected to be rolled out by the end of September, 2020. 
 
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through below links 

Query 2.1 : Change size of Description column > Press Reset Persist > fails to reset (problem with this column only) 
We have confirmed it as a bug and logged the defect report “ResetPersistData not resets GridColumn size when Width property is not set in GridColumn. Thank you for taking time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle) and including the defect fix in our upcoming  bi-weekly release which is expected to be rolled out by the end of September, 2020. 
 
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through below links 

Query 3 : Click on the Transaction Date Filter and set a date range > Save Persists > change the date range filter > Apply Persist > Filter is not reset 
Based on this scenario, we suggest you to set the @bind-StartDate and @bind-EndDate property values of SfDateRangePicker in the ApplyPersist method to achieve this requirement. In the below code, we have maintained two variables PersistStartDate and PersistEndDate. When the SavePersist method is called we have fetched the start and end date values and assigned to PersistStartDate and PersistEndDate. Now when the ApplyPersist is called we have assigned the already saved values(PersistStartDate, PersistEndDate) to StartDate and EndDate. 

 
<FilterTemplate>    <SfDateRangePicker @bind-StartDate="StartDate" @bind-EndDate="EndDate" @ref="TransactionDateRangePicker">        <DateRangePickerEvents OnClose="TransactionDateFilterChange"></DateRangePickerEvents>    </SfDateRangePicker>                                </FilterTemplate>
 
 
public DateTime? StartDate { getset; } 
public DateTimePersistStartDate { getset; } 
 
public DateTime? EndDate { getset; } 
public DateTimePersistEndDate { getset; } 

public async Task SavePersist(){  PersistStartDate = TransactionDateRangePicker.StartDate;  PersistEndDate = TransactionDateRangePicker.EndDate;  TimeGridPersistData = await this.TimeGrid.GetPersistData();  NotificationService.DisplayNotification("Testing""Persist Data Saved""1000");} public async Task ApplyPersist(){  StartDate = PersistStartDate;  EndDate = PersistEndDate;  if (TimeGridPersistData != "")  {    await this.TimeGrid.SetPersistData(TimeGridPersistData);    NotificationService.DisplayNotification("Testing""Persist Data Applied""1000");    this.StateHasChanged();    await Task.Delay(100);  }}

Query 4 : The problem is (I think) that the data is not always properly captured during the Destroyed Event leading to an error on the subsequent Created event. 
We are currently checking this scenario from our side. We will update you further details in two business days. Until then we appreciate your patience. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



SY Seo Yun September 4, 2020 03:02 PM UTC

I have been playing with the GetPersistData and SetPersistData in the DataGrid. I would like to store the persistent data in our database so that I can re-apply when the user re-opens the grid. I have some questions.


RS Renjith Singh Rajendran Syncfusion Team September 7, 2020 01:44 PM UTC

Hi Richard/Seo, 

Query 4 : The problem is (I think) that the data is not always properly captured during the Destroyed Event leading to an error on the subsequent Created event. 
We suggest you to fetch the persisted data in the OnActionComplete event(as like you have updated in previous update) instead of previously suggested Destroyed event.  
 
Query : I have tried using the ActionComplete event instead of the Destroyed event to store persist data after every change by the user. You will see it commented out in the code. But this too has problems: 
Issue 1 : Again the filtering is not persisted 
We are also facing the Filter data not get persisted problem, when using the persisted data fetched using OnActionComplete event of Grid. We have confirmed “Filter data is not persisted in Grid when calling SetPersistData in Created event” as a bug and logged defect report for the same. Thank you for taking time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle) and including the defect fix in our upcoming  bi-weekly release which is expected to be rolled out by the end of September, 2020. 
 
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through below links 

Issue 2 : A column size change is not captured by this event.  I tried using ResizeStopped event to handle this, but this is too chatty / does not capture persist data correctly 
We have resolved this problem with our latest version 18.2.0.56. So please upgrade to our latest version and capture the resize persist information using ResizeStopped event(as like you have done in your application) to overcome the problem you are facing. 

Query : I have some questions. 
Please refer our below online UG documentation for more details. If you need any further assistance. Kindly get back to us with your query to proceed further. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



DI Ditchford September 7, 2020 11:32 PM UTC

Thanks for the feedback and the defect report references.

I still have an issue with one of the items. The ResizeStopped event even after upgrading to 18.2.0.56 is still an issue. I have attached an amended project.  This project uses:

The ActionComplete event to capture persist data for most things (sort, filter, search, column move, column selected etc)
The ResizeStopped event to capture persist data for column resizing
The Created event to apply the persist data on reload of page

This seems to be the preferred method (rather than using the Destroy event to capture persist data).  To recreate the problem(s)

- Goto Persist02 Page
- Resize the customer column (you will be inundated with persist data saved messages as the event is firing multiple times)
- Goto home page
- Goto back to Persist02 Page.

I have 2 problems with this:

1. The event is firing multiple (10+) times.  I will be writing to the database so really cannot be writing this many times (this event is still too chatty)
2. The column size is not persisted anyway.

Look forward to hearing from you.

Regards

Attachment: BlazorApp1_900d5e37.zip


RS Renjith Singh Rajendran Syncfusion Team September 8, 2020 12:50 PM UTC

Hi Richard, 

Thanks for your update. 

Query 1 : The event is firing multiple (10+) times.  I will be writing to the database so really cannot be writing this many times (this event is still too chatty) 
We suggest you to use as like the below code to trigger the SavePersist method once in ResizeStopped event handler. In the below code, we have fetched the current resize column in OnResizeStart event. And based on this current resize column value we have called the SavePersist method in ResizeStopped event handler.  

Please refer and use like the codes below, 

 
<GridEvents OnToolbarClick="ToolbarClicked" Destroyed="Destroyed" OnResizeStart="OnResizeStart" ResizeStopped="ResizeStopped" ... TValue="TimeModel"></GridEvents> 
 
public async void ResizeStopped(ResizeArgs args){    if(args.Column.Field == CurrentColResize)    {        await SavePersist();        CurrentColResize = "";    }}public string CurrentColResize { getset; }public async void OnResizeStart(ResizeArgs args){    CurrentColResize = args.Column.Field;}
 
Query 2 : The column size is not persisted anyway. 
We have confirmed “Problem with getting resize persisted value when calling GetPersistData in ResizeStopped event” as a bug and logged defect report for the same. Thank you for taking time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle) and including the defect fix in our upcoming  bi-weekly release which is expected to be rolled out by the end of September, 2020. 
 
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through below links 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 


Marked as answer

DI Ditchford September 12, 2020 04:35 AM UTC

Hello

Great, thank you.  I think that now covers everything (with the defects in progress).

Regards


RS Renjith Singh Rajendran Syncfusion Team September 14, 2020 07:04 AM UTC

Hi Richard, 

Thanks for your update. 

Please follow up on the corresponding feedback links for tracking the current status of your request and review the proposed resolution timeline. You can contact us for any further inquiries through the corresponding feedback links. 
 
Regards, 
Renjith Singh Rajendran 



Loader.
Up arrow icon