按钮单击在Celltemplate角度网格中不起作用

Button click does not work in Celltemplate angular grid

本文关键字:网格 不起作用 单击 Celltemplate 按钮      更新时间:2023-12-02

我正在尝试使用celltemplate。但点击事件并没有起作用。

    $scope.format = function(val){
            return val.replace(/'//g, "");
        };
        var executionColumns = {
            data: [],
            enableSorting: true,
            paginationPageSizes: [25, 50, 75],
            paginationPageSize: 25,
            enableColumnMenu: true,
            enableFiltering: true,
            columnDefs: [
              { field: 'StartDate', cellTemplate: '<button ng-click="format (row.entity)">log</button>' },
              { field: 'Status' },
            ]
        };

那么我该怎么办呢?怎么了?

它对我来说就像第二个代码

         columnDefs: [
          { field: 'StartDate', cellTemplate: '<button ng-click="format(grid.getCellVale(row.entity)   )">log</button>' },
          { field: 'Status' },
        ]

或者将您的格式化函数移动到定义为的外部作用域

 $scope.globalExternalScope = {
       format:function(entity){..........}
    }

然后使用类似的模板

         columnDefs: [
          { field: 'StartDate', cellTemplate: '<button ng-click="getExternalScopes().format(grid.getCellVale(row.entity)   )">log</button>' },
          { field: 'Status' },
        ]

使用<button ng-click="grid.appScope.format (row.entity)">log</button>

它现在对我有用!

如果您使用的是.component,则在其中渲染ui-grid,并且您的方法定义为: this.handleClick = function(){...}

它将在cellTemplate中通过 cellTemplate: '<button ng-click="grid.appScope.$ctrl.handleClick()">log</button>' }