Angular ui-grid:如何根据第一个网格的行选择值刷新第二个网格

时间:2016-03-07 19:28:07

标签: angularjs angular-ui-grid

有2个网格grid1 grid2。 我的要求是:当我在grid1中选择一行时,grid2应该刷新。我可以根据我的服务中的行选择来获取修改后的数据,但是我无法将其显示在grid2上。 我试过了

$scope.grid2 = function () { $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL);
$scope.gridApi.core.refresh();}

以上两者都在grid1 onRegisterAPI内的RowSelectionChanged事件中

$scope.gridOptions.onRegisterApi = function (gridApi) {
    $scope.gridApi = gridApi;
    $timeout(function () {
        $scope.gridApi.selection.on.rowSelectionChanged($scope, function (row) {
            $scope.value = row.entity.MVE_VEID;
            console.log($scope.value);
            $scope.contractvalues = contracts.query({ id: $scope.value });
            console.log($scope.contractvalues);
            $scope.gridoptions2 = function () { $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL);  $scope.gridApi.core.refresh(); }
            $scope.refresh = true;

        });

如何刷新grid2中的数据?

现行守则: contrcontroller.js

<pre>

    angular
        .module('VendorApp')
        .controller('ang_contcontroller', ang_contcontroller);

    ang_contcontroller.$inject = ['$scope','contracts'];

    function ang_contcontroller($scope, contracts) {

        $scope.contractvalues = contracts.query({ id: $scope.value });
        $scope.gridoptions2 = {
            enableRowHeaderSelection: false,
            multiSelect: false,
            enableRowSelection: true,
            enableSelectAll: true,
            enableSorting: true,
            enableFiltering: true,
            enablePagination: true,
            enablePaginationControls: true,
            paginationCurrentPage: 1,
            paginationPageSize: 100,
            maxVisibleColumnCount: 200,
            columnDefs: [
              { name: 'CONTRACTID', field: 'MCO_COID' },
              { name: 'NAME', field: 'CO_DESC' },
              { name: 'VENDORID', field: 'MCO_VEID' }
            ],
            data: $scope.contractvalues

        };
        $scope.gridoptions2.onRegisterApi = function (gridApi) {
            $scope.gridApi2 = gridApi;
        }

    }


vencontroller.js

    $scope.gridOptions.onRegisterApi = function (gridApi) {
                $scope.gridApi = gridApi;
                $timeout(function () {
                    $scope.gridApi.selection.on.rowSelectionChanged($scope, function (row) {
                        $scope.value = row.entity.MVE_VEID;
                        console.log($scope.value);
                        $scope.contractvalues = contracts.query({ id: $scope.value });
                        console.log($scope.contractvalues);
                        $scope.gridoptions2 = {};
                        $scope.gridoptions2.data = $scope.contractvalues;
                        //$scope.gridApi2.refresh();
                        $scope.grid2 = function () {
                            $scope.gridApi2.core.notifyDataChange(uiGridConstants.dataChange.ALL);
                            $scope.gridApi2.core.refresh();
                        };
                        //$scope.grid2 = function () {
                        //     $scope.gridoptions2 = angular.copy($scope.gridoptions2);
                        //     $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL= function () { $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL); },$scope.gridApi.core.refresh(); );
                        // }
                        //$scope.refresh();
                        //$scope.gridoptions2 = function () { $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL); }
                    });

                });
    <code>

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您需要更新grid2的数据 你写道,你能够修改基础数据说“newData”。 将此新数据分配给“$ scope.gridoptions2.data”

$ scope.gridoptions2.data = newData;