ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Restore state timing issue

Open BertusVanZyl opened this issue 11 years ago • 10 comments

When is it safe to call restore described here? http://ui-grid.info/docs/#/tutorial/208_save_state

On page load, restore only works properly if I add a delay. But how do I know what the delay should be? Could someone please define when it is safe to call restore? At least then I can check if it is safe every 500ms or so, until it is safe to call restore.

Thank you.

BertusVanZyl avatar Oct 15 '15 14:10 BertusVanZyl

I'm having a similar issue, 500ms seems to work for me. But does not restore scroll bar, which is minimal in my case but still an issue that this is not working as advertised. We should definitely get a plunkr going as the docs version does work.

mikehuebner avatar Oct 20 '15 01:10 mikehuebner

I have found that calling restore method right after the data has been set works. So I use $q to queue everything up so that I can know for sure when all my ajax calls are done, and AFTER the data has been set on the $scope, I then call restore. I have seen no issues with this so far.

This makes sense, ui-grid has no way of knowing when your data loading is complete, however, I think the documentation should guide the developer a bit more. In fact, I am still not 100% sure if this is the correct way.

Could someone shed some light?

BertusVanZyl avatar Oct 20 '15 07:10 BertusVanZyl

I think this is the issue I am seeing. I have extended the tutorial plnkr to show the issue.

http://plnkr.co/edit/isrWNAiV19MFE4de2trc

  • Click load to load data.
  • Select some rows
  • Click load to "refresh" the data, the selected rows should be preserved but they are not.
  • Click Restore to show that the restore really does something.

shaneholder avatar Nov 04 '15 21:11 shaneholder

The restore state has a couple of modes to drive selection - one based on the id of the rows, one based on the order and position within the list (obviously less accurate). Have you played with those options?

PaulL1 avatar Nov 04 '15 21:11 PaulL1

In my system, I am using the saveRowIdentity of the grid options, is that what you're referring too?

shaneholder avatar Nov 04 '15 21:11 shaneholder

Yes. I'd put some breakpoints in the restore code to see what happens when it attempts to identify the row with that identity - and see whether the problem is that the row isn't there yet, or something else.

PaulL1 avatar Nov 04 '15 21:11 PaulL1

FWIW I put my grid restore code inside a $timeout(function () {restoreGrid();}, 0); and the selections are being restored.

shaneholder avatar Nov 04 '15 21:11 shaneholder

+1

jihunleekr avatar Mar 09 '16 03:03 jihunleekr

@PaulL1 - first, a million thanks for your great work and contribution with ui-grid. It's amazing and I love it.

For my use I have datasets that are rather large (like 100k+) and can take some time to fetch from the backend. Right now I have a load( ) func that fetches 10k at a time and appends to the end.

All my users want to state-save is the columns displayed, their width, current filter, and sort. I can achieve that only by setting another timeout at the end of the last batch from the backend and then restoring state. Anything else I try results in the state being restored and then reverting back to default.

I'm pretty sure I should be able to restore the state after the first batch is fetched from the backend and then as each subsequent batch comes in, they don't change the layout. Alas, that's not happening.

I currently have:

    saveFocus: false,
    saveScroll: false,
    saveSelection: false,
    saveGroupingExpandedStates: true,

Should I be falsing some more than these to acheive my functionality?

Also - if appending a new row throws the whole layout, I guess when we append new rows we have to append the row, then restore state again, correct?

  • thanks again!

richardpickett avatar Nov 16 '16 04:11 richardpickett

@PaulL1 i tried restoring the state with $timeout but still the next event is not waiting for the restore state to complete. Check out the below plunker: http://plnkr.co/edit/LAMZvOkpx6jsD4CWSz04?p=preview In here the column is getting resized while filtering. So i am trying to save and restore state on each filter event. $scope.gridApi.core.on.filterChanged($scope, saveState); $scope.gridApi.core.on.filterChanged($scope, restoreState);

it is working when i give some time between my filtering. If i type fast to filter then the column is getting resized to default. Any help would be appreciated.

smurugesan2016 avatar Jan 03 '17 15:01 smurugesan2016