Button click does not work in Celltemplate angular

2019-03-03 03:11发布

I m trying to work with celltemplate. But click event did not work.

    $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' },

            ]

        };

So what should I do? What is the wrong?

3条回答
疯言疯语
2楼-- · 2019-03-03 03:25

In case you are using .component inside of which you render a ui-grid and your method is defined as: this.handleClick = function(){...}

It will be available to you in cellTemplate via cellTemplate: '<button ng-click="grid.appScope.$ctrl.handleClick()">log</button>' }

查看更多
Root(大扎)
3楼-- · 2019-03-03 03:27

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

it is working for me now!

查看更多
劳资没心,怎么记你
4楼-- · 2019-03-03 03:49

It works for me like the 2nd code

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

        ]

or move your format function to an externalscope defined as

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

and then use the template like

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

        ]
查看更多
登录 后发表回答