Angularjs click事件在iggrid列中不起作用

时间:2013-11-22 07:25:41

标签: javascript angularjs wijmo wijgrid

我在角js中使用wijgrid组件我遇到了无法在它上执行click事件的问题。在wijgrid html组件未编译,找到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)
} 

这里提交代码函数没有调用,在视图源中该函数显示id和status ..这意味着它没有在wijgrid模块中编译请帮我提供解决方案。我试着编译代码$ compile($ sumitBtn)($ scope)但它不起作用,请建议我s0lution

2 个答案:

答案 0 :(得分:1)

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(我的应用程序具有可变数量的列,因此这不是我的选项)。如果使用cellFormatter,你可以引用args.container而不是args。$ cell。

以下是wijmo解释的链接:http://wijmo.com/topic/wig-grid-with-angularjs-how-to-handle-click-on-a-link-in-a-cell/

答案 1 :(得分:0)

我使用cellformatter方法得到了解决方案,我根据我的要求更改了代码

$scope.formatter = function(args) {
if(args.row.dataRowIndex < 0 ) 
return false;
args.$container
.html($compile(
args.formattedValue)
($scope));
return true;    
}   
相关问题