我在angular js中使用wijgrid组件,我遇到了无法在其上执行点击事件的问题。在wijgridhtml组件未编译的情况下,找到html代码
<wij-grid id = "dataGrid" allow-sorting="true" data="data" columns-autogeneration-mode="none" allow-paging="true" >
<columns>
<column data-key="name" header-text="Name"></column>
<column data-key="address" header-text="Address" ></column>
<column data-key="submit" header-text="Submit"></column>
</columns>
</wij-grid>
和我的角js代码
$http.get(url,data).success(
loadData);
function loadData(responseData) {
if (responseData != null) {
var data = responseData;
for (index = 0; index < data.length; index++) {
data[index].address = data[index].addressLineOne+","+data[index].addressLineTwo;
$SubmitBtn = "<a href='javascript:void(0);ng-click='submitCode("+data[index].reviewId+",true)'>Approve</a>"; data[index].submit=$ASubmitBtn;
}
$scope.data = data;
$("#content").wijtabs();
}
}
$scope.submitCode= function(id, status) {
alert(id+" "+status)
}
HERE提交代码函数没有调用,在视图源中,该函数显示id和状态。。这意味着它不是在wijgrid模块中编译的,请帮助我提供解决方案。我试图编译代码$compile($sumitBtn)($scope),但它不起作用,请建议我使用解决方案
Wijmo意识到了这个问题,并表示这是一个已知的错误。我使用的解决方法是:
$scope.cellStyleFormatter = function(args) {
if ((args.row.type & wijmo.grid.rowType.data) && (args.row.state & wijmo.grid.renderState.rendering)) {
var content = args.$cell[0].innerHTML;
//Here I have button html already in my grid data, using
//'my-link-class' css
if(content.indexOf("my-link-class") > -1) {
var scope = angular.element("#grid-container").scope();
args.$cell
.empty()
.append($(content).click(function () {
scope.myControllerClickHandler();
})
);
}
return true;
}
};
我这样声明我的网格:
<wij-grid data="template.model.content" allow-editing="false" cellStyleFormatter="cellStyleFormatter">
<columns>
<column dataKey="col_0" ></column>
</columns>
</wij-grid>
我使用上面的cellStyleFormatter,因为我可以将其全局应用于整个网格。如果你提前知道列,你可以使用cellFormatter(我的应用程序有可变数量的列,所以这对我来说不是一个选项)。您将引用args.container而不是args$单元格(如果使用cellFormatter)。
以下是wijmo解释的链接:http://wijmo.com/topic/wig-grid-with-angularjs-how-to-handle-click-on-a-link-in-a-cell/
我使用cellformatter方法得到了解决方案,我根据我的要求更改了代码
$scope.formatter = function(args) {
if(args.row.dataRowIndex < 0 )
return false;
args.$container
.html($compile(
args.formattedValue)
($scope));
return true;
}