UI-Grid with button in custom cell template - How to cancel row select event?

非 Y 不嫁゛ 提交于 2019-12-19 10:05:06

问题


I am using ui-Grid v 3.0.1.

I have a custom cell template for a particular column which displays a button in each row. I have attached a ng-click attribute which calls the appScope to trigger some action.

All works beautifully.

However, the clicking of the custom template button also causes the selection of the row in question to be toggled.

I need to prevent this from happening.

i.e. a click to the custom template button should leave the current row's selection status as it was.

I suspect I need to cancel the row selection event somehow.

Can anyone point me in the right direction?

vm.gridOptions = {
        data: "vm.myGridData",
        columnDefs: [
            { field: "Col1", displayName: "Col1", width: 100 },
            { field: "Col2", displayName: "Col2", width: 200 },
            { name: " ", cellTemplate: "<div><button ng-click='grid.appScope.displayRecord(row.entity)'><i class='fa fa-search'></i></button></div>" }
        ],
        enableRowSelection: true,
        enableSelectAll: true,
        showGridFooter: true,
        multiSelect: true,
        enableSorting: true,
        enableFiltering: true,
        enableFullRowSelection: true,
        enableRowHeaderSelection: true
    };

回答1:


Just add

$event.stopPropagation();

to the ng-click attribute as you can see in this plunker.

You can chain javascript calls inside your ng-click attribute just by writing them one next to another with a ; as a separator like this:

ng-click = "instructionOne(); instructionTwo(argument); $event.stopPropagation();"


来源:https://stackoverflow.com/questions/34224228/ui-grid-with-button-in-custom-cell-template-how-to-cancel-row-select-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!