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

Persist expanded/selected rows

Open jawaharlalt opened this issue 9 years ago • 3 comments

Hi

How to persist expanded rows and selected rows after server data sync

Thanks

jawaharlalt avatar Feb 16 '17 09:02 jawaharlalt

Hi, so is there a solution? thanks

sativ01 avatar Oct 17 '18 11:10 sativ01

Hi

Seems there is no official solution for that. I did manage to achieve that through 'onRegisterApi' ui grid event.

Note: This solution might be ugly but, worked for me :). You can try this until found the better solution.

onRegisterApi: function( gridApi ) { $scope.gridApi = gridApi;

  $scope.gridApi.core.registerRowsProcessor(function(rows, columns) {

    rows.forEach(function(row) {
        if ($scope.grid_demo.expandedRows[row.entity.unique_key] != null) {
            if (row.treeNode == null) row.treeNode = {};
            row.treeNode.state = $scope.grid_demo.expandedRows[row.entity.unique_key].state;
        }
    });
	
	// $scope.gridApi.saveState.restore($scope, $scope.grid_demo.state);
	
	    $(".grid_html_selector .ui-grid-viewport:eq(0)").scrollTop($scope.grid_demo.uiscrollTop);
    return rows;
}, 399);



 $scope.gridApi.treeBase.on.rowExpanded($scope, function(row) {
    $scope.grid_demo.expandedRows[row.entity.unique_key] = { state: 'expanded' };
        });
$scope.gridApi.treeBase.on.rowCollapsed($scope, function(row) {
    $scope.grid_demo.expandedRows[row.entity.unique_key] = { state: 'collapsed' };
});
}

jawaharlalt avatar Oct 17 '18 11:10 jawaharlalt

@jawaharlalt , thanks for the reply and sample code! I was thinking about similar solution, and seen few of them in stackoverflow. It's a pity there's no property to persist row's state in grid-ui...

Good luck!

sativ01 avatar Oct 18 '18 07:10 sativ01