简体   繁体   English

Angular中的UI网格刷新

[英]UI Grid refresh in Angular

From a different controller a modal pop up opens. 从另一个控制器打开一个模式弹出窗口。 On closing of the modal pop up , I will do something and I want to transfer the data to a different controller which populates a UI grid and is bound to $scope.searchResultsGridOptions . 在关闭模式弹出窗口时,我将做一些事情,并将数据传输到另一个控制器,该控制器填充UI网格并绑定到$scope.searchResultsGridOptions

So in my ABCCtrl.js file : 所以在我的ABCCtrl.js文件中:

On closing of a modal , I do : 在关闭模式时,我会:

$("#iConfirmationModal").on('hidden.bs.modal', function () {
    $state.go('transaction.search.results', {});
    //I close all the modals
    $uibModalStack.dismissAll();
    //I get the stored search criteria 
    var searchResultsParam = TransactionDataServices.getSavedSearchParams();


    //Using them I hit the web service again and get the data to reload the UI Grid 
    TransactionServices.getTransactionAdvSearchResults(searchResultsParam).then(function (result) {

            //I got the result
            console.log(result);
            /Now I want to reload the grid with this data , but the grid scope object which binds to this , is in separate controller
            searchResultsGridOptions.data = result;
        });
    });

In DEFCtrl.js 在DEFCtrl.js中

I have 我有

    getSearchResultsGridLayout: function (gridOptions, uiGridConstants, datas) {
        gridOptions.multiSelect = false;
        //  gridOptions.data.length = 0;
        // gridOptions.data = '';
        gridOptions.data = datas;
        console.log("Grid Data ");
        console.log(datas);
        console.log(gridOptions.data);
        angular.element(document.getElementsByClassName('grid')[0]).css('height', '0px');
        // console.log(datas.length);
        return gridOptions;
    }

But how would I only change the data only when modal closes ? 但是,如何仅在模式关闭时才更改数据?

Rest of the time it should not refresh the Grid ? 其余时间是否应该不刷新Grid?

Or , 要么 ,

Is there any way when on closing of the modal , instead of simply go back to the state using $state.for() and seeing the previous unrefreshed data , I can see the refreshed data ? 关闭模态时,有什么办法,而不是简单地使用$state.for()返回状态并查看先前未刷新的数据,而是可以看到刷新的数据?

Hi I think you do not need to call the "TransactionServices.getTransactionAdvSearchResults()" in the "ABCCtrl" controller but you have to call it in the "DEFCtrl" controller. 嗨,我认为您不需要在“ ABCCtrl”控制器中调用“ TransactionServices.getTransactionAdvSearchResults()”,但是您必须在“ DEFCtrl”控制器中调用它。

You need to find a way to pass the "searchResultsParam" extracted in "ABCCtrl" to "DEFCtrl". 您需要找到一种方法,将“ ABCCtrl”中提取的“ searchResultsParam”传递给“ DEFCtrl”。

You can use the ui-router state parameters . 您可以使用ui-router状态参数 You can specify a parameter in the "transaction.search.results" state, like this: 您可以在“ transaction.search.results”状态下指定参数,如下所示:

.state('transaction.search.results', {
    ...
    params: {
        searchResultsParam: null
    }
   ...
})

And in the "ABCCtrl" pass it to the state: 并在“ ABCCtrl”中将其传递给状态:

$("#iConfirmationModal").on('hidden.bs.modal', function () {
    //I close all the modals
    $uibModalStack.dismissAll();
    //I get the stored search criteria 
    var searchResultsParam = TransactionDataServices.getSavedSearchParams();
    $state.go('transaction.search.results', {searchResultsParam: searchResultsParam});

Then, in "DEFCtrl" you can read it and call the "TransactionServices.getTransactionAdvSearchResults()" method. 然后,在“ DEFCtrl”中可以读取它并调用“ TransactionServices.getTransactionAdvSearchResults()”方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM