可扩展网格子网格无法访问外部作用域

时间:2016-07-08 05:25:19

标签: angularjs angular-ui-grid

我无法从可扩展ui- grid中定义的cellTemplate访问控制器中定义的方法。 ng-click =“editComments()”在cellTemplate中以可扩展的ui- grid编写。 $ scope.editComments在控制器中定义。您可以在下面找到代码

      <div id="grid1" ui-grid="gridOptions2" ui-grid-selection ui-grid-exporter ui-grid-pinning ui-grid-expandable class="grid"></div>
     <div ui-grid="row.entity.subGridOptions" style="height:150px;"></div>


       $scope.gridOptions2 = {
            enableSorting: true,
            enableFiltering: true,
            showGridFooter: true,
            showColumnFooter: true,
            exporterMenuCsv: true,
            enableGridMenu: true,

            expandableRowTemplate: 'App/Post/expandableRowTemplate.html',
            expandableRowHeight: 150,
            //subGridVariable will be available in subGrid scope
            expandableRowScope: {
                subGridVariable: 'subGridScopeVariable'
            },
            onRegisterApi: function (gridApi) {
                $scope.gridApi = gridApi;
            },
            columnDefs: [
              {
                  field: 'title', enableSorting: false, enableFiltering: false, aggregationType: uiGridConstants.aggregationTypes.sum, displayName: 'Id', headerCellClass: 'blue',
                  footerCellTemplate: '<div class="ui-grid-cell-contents" style="background-color: Red;color: White">custom template:{{col.getAggregationValue()}}</div>',

              },
              {
                  field: 'description', headerCellClass: $scope.highlightFilteredHeader, filter: {
                      condition: uiGridConstants.filter.ENDS_WITH,
                      placeholder: 'ends with'
                  },
                  cellTooltip: function (row, col) {
                      return 'Name: ' + row.entity.ProductName;
                  }

              },
              { field: 'by', enableSorting: false },
                { field: 'tags', enableSorting: false },
               { field: 'url' },

                 {
                     name: 'Action', enableSorting: false, enableFiltering: false,

                     cellTemplate: '<button class="btn primary"  ng-click="grid.appScope.edit(row.entity,$event)">Edit  Me</button>' + ' ' +
                         '<button class="btn primary"  ng-click="grid.appScope.Delete(row.entity,$event)">Remove  Me</button>'
                 },

            ],

        };

     $scope.getAll = function () {
            $http({
                method: 'GET',
                url: appSetting.ServerPath + 'api/Post/GetAll',
            }).success(function (data) {
                for (i = 0; i < data.length; i++) {
                    var hjy = data[i].tags;
                    data[i].subGridOptions = {
                        columnDefs: [{ field: "dateCreated" }, { field: "like" }, { field: "message" }, { field: "user" },

                                {
                                    name: 'Action', enableSorting: false, enableFiltering: false,

                                    cellTemplate: '<button class="btn primary"  ng-click="grid.appScope.editComments(row.entity,$event)">Edit  Me</button>' + ' ' +
                                        '<button class="btn primary"  ng-click="grid.appScope.Delete(row.entity,$event)">Remove  Me</button>'
                                }
                        ],
                        data: data[i].comments
                    }
                }
                $scope.gridOptions2.data = data;
            }).error(function () {
                alert("error");
            });
        }



        $scope.editComments = function (item, event)
        {
            alert(item);
        }

0 个答案:

没有答案