Stored grid Option 不应用特定样式

Stored grid Option does not apply the specific styles

我正在开发一项功能,用户可以在其中自定义网格(添加、分组、排序、聚合等),然后可以将其另存为模板。

我可以通过单击按钮来检索网格选项,如下所示。

JSON.stringify($scope.gridOptions)

然而,当我将其用作网格选项时,网格会加载,但缺少分组、排序和聚合。如果我分析网格选项,我仍然有它们。

我认为对于您的情况,您可以使用 angular-ui-grid 的 built-in 保存和恢复状态功能。这意味着网格将带回您想要的设置并正确显示它们。您还可以控制还原哪些设置(例如排序、过滤等),哪些不还原。

http://ui-grid.info/docs/#/tutorial/208_save_state

一些示例代码

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

    // I store when the user changes a filter, but you could
    // instead store on the user clicking a button or any other event
    $scope.gridApi.core.on.filterChanged($scope, function() {
        var state = gridApi.saveState.save();
        SomeServiceOfMineForStoringStuff.storeState(state);
    });
}

稍后...

var savedState = SomeServiceOfMineForStoringStuff.getState();

if (savedState) {
    $scope.gridApi.saveState.restore($scope, savedState);
}

您可以使用ui-grids 保存和恢复功能。 Save and Restore

  1. 注入 'ui.grid.saveState' 模块。
  2. 将 'ui-grid-save-state' 添加到您的网格 html。
<div id="gridSaveState" ui-grid="gridOptions" ui-grid-save-state class="grid"></div>

然后您可以通过保存格式化的 JSON 来存储 ui-网格状态,并从该数据恢复。