【问题标题】:ng-grid + rowTemplate not working. What am I missing?ng-grid + rowTemplate 不起作用。我错过了什么?
【发布时间】:2014-03-11 01:49:07
【问题描述】:

我正在尝试使用我的 ng-grid 将 ngdblclick 元素添加到每一行。有用!但是,我再也看不到我的数据了。我可以看到行但没有数据。数据在那里,似乎绑定正确。我知道这一点是因为我创建了一个名为 selectedRows 的列表,该列表绑定到 gridOptions 中的 selectedItems。当我单击每一行时。我看到我的数据显示在 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: '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'}],
   };
});

【问题讨论】:

    标签: angularjs ng-grid


    【解决方案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'}],
       };
    

    【讨论】:

    • 嘿@Cabel,感谢您的回复。当我提交这个问题时,我刚刚开始使用 JS、Angularjs 和 ngGrid。正如您在我的代码中看到的那样,我缺少很多东西。我最终弄清楚我做错了什么。但是,对于那些偶然发现此页面的人来说,这仍然是一个很好的例子。再次感谢。
    猜你喜欢
    • 2015-05-27
    • 2020-09-14
    • 1970-01-01
    • 2020-08-26
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-23
    相关资源
    最近更新 更多