ng-grid + rowTemplate不工作。我错过了什么?

时间:2014-02-04 21:08:36

标签: angularjs ng-grid

我正在尝试使用ng-grid将ngdblclick元素添加到每一行。有用!但是,我再也看不到我的数据了。我可以看到行但没有数据。数据似乎是正确绑定的。我知道这是因为我创建了一个名为selectedRows的列表,它绑定到gridOptions中的selectedItems。当我点击每一行时。我看到我的数据显示在html中

 tag. See below for my code. 

$scope.tableData=[]; $scope.tableData=[{id:'10203040', status:'Submitted'}, {id:'10203040', status:'Submitted'},] $scope.selectedRows=[]; var rowTempl = '<div ng-dblClick="onDblClickRow(row)" ng-style="{ \'cursor\': row.cursor }" ng-repeat="col in renderedColumns" '+'ng-class="col.colIndex()" class="ngCell{{col.cellClass}}"><div class="ngVerticalBar" ng-style="{height:rowHeight}" ng-class"{ngVerticalBarVisible:!$last}">$nbsp;</div><div ng-cell></div></div>'; $scope.onDblClickRow = function(row){ alert("Double Click works!"); }; $scope.gridOptions = { data: 'myData', selectedItems:$scope.selectedRows, showColumnMenu:true, showFilter:false, enableColumnResize:true, enableRowSelection:true, showGroupPanel:false, rowTemplate: rowTempl, columnDefs: [ {displayName:'Name', field:'name'}, {displayName:'Age', field:'age'}], }; });

1 个答案:

答案 0 :(得分:1)

我无法运行您的代码。您的columDefs字段与tableData键不匹配。此外,gridOptions数据具有'myData'而不是'tableData'。我不确定您使用了哪些代码,因为您说您可以在HTML中看到数据。

无论如何,这有效:

$scope.tableData=[];

$scope.tableData=[{id:'10203040', status:'Submitted'},
              {id:'10203040', status:'Submitted'}];

$scope.selectedRows=[];

var rowTempl = '<div ng-dblClick="onDblClickRow(row)" ng-style="{ \'cursor\': row.cursor   }" ng-repeat="col in renderedColumns" '+'ng-class="col.colIndex()" class="ngCell{{col.cellClass}}"><div class="ngVerticalBar" ng-style="{height:rowHeight}" ng-class"{ngVerticalBarVisible:!$last}">$nbsp;</div><div ng-cell></div></div>';

$scope.onDblClickRow = function(row){
 alert("Double Click works!");
};


$scope.gridOptions = { 
    data: 'tableData',
    selectedItems:$scope.selectedRows,
    showColumnMenu:true,
    showFilter:false,
    enableColumnResize:true,
    enableRowSelection:true,
    showGroupPanel:false,
    rowTemplate: rowTempl,
    columnDefs: [
      {displayName:'Name', field:'id'},
      {displayName:'Age', field:'status'}],
   };