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

Grid state not restored when the grid is toggled between 2 tabs in ng-if

Open AdityaJitu opened this issue 11 years ago • 3 comments

Hi, I am using v3.0.0-RC.18-92a8836 of UI-Grid. I am having grid each in a single tab. As such I am having two tabs. I am trying to save the state of the grid as & when the user changes the tabs. Suppose the user resized the column of the grid in first tab then before moving to the 2nd tab I am saving the grid State in localStorage. Then again after moving to the first grid I am trying to apply the state the I have saved in localStorage using the restoreState() function but the changes are not getting displayed.

I am toggling the grids using ng-if so that in DOM only a single grid persists.

AdityaJitu avatar Jun 30 '15 12:06 AdityaJitu

Try this directive rather than ng-if.

This works as the scope isn't trashed.

 directive('gridSize', function ($timeout, gridUtil) {
     return {
        require: 'uiGrid',
        scope: true,
        link: function ($scope, $elm, $attr, uiGridCtrl) {

            function size() {
                var newGridHeight = gridUtil.elementHeight($elm);
                var newGridWidth = gridUtil.elementWidth($elm);

                uiGridCtrl.grid.gridHeight = newGridHeight;
                uiGridCtrl.grid.gridWidth = newGridWidth;

                uiGridCtrl.grid.queueGridRefresh();
            }

            var deReg = $scope.$watch($attr.gridSize, function(n, o) {
                if (!n) {
                    return;
                }

                size();
            });


            $scope.$on('$destroy', function () {
                deReg();
            });
        }
    };
 });

MattOakley avatar Jun 30 '15 14:06 MattOakley

I think we'd need a plunker to help much with this. saveState and restoreState appear to still be working fine, so presumably it's something in the way that you're applying it.

PaulL1 avatar Jul 19 '15 08:07 PaulL1

@Paul1 It is working fine. It was a minor mistake from my side. Therefore I am closing this ticket.

AdityaJitu avatar Jul 19 '15 08:07 AdityaJitu