我尝试使用 Ng-table 创建一个表格 View ,它可以通过 AngularJS 参数进行控制。
要控制标题文本,我需要将其放在 data-title 或 ng-data-title 中(例如:data-title="'Test'")
代码片段:
<td ng-repeat="v in tableSettings.data" data-title="v.name">
{{v.data?v.data(row):row[v.id]}}
</td>
完整代码:
<table ng-table="table" class="table" show-filter="{{tableSettings.filter}}">
<tr ng-repeat="row in $data">
<td ng-repeat="v in tableSettings.data" ng-click="tableSettings.click(row)" ng-attr-data-title="'{{v.name}}'"
ng-if="v.type!='switch'"
sortable="'{{sortable?sortable:v.id}}'">
{{v.data?v.data(row):row[v.id]}}
</td>
</tr>
</table
当我尝试将 Angular 解析到其中时,我只得到错误:(按查看错误)
有没有办法修复它,甚至可以从 AngularJS 手动解析它?
最佳答案
好的,问题是 data-title
属性是要与静态文本(众所周知的列)一起使用的,例如 data-title="'My first column'"
如果您需要的是动态列,则必须使用 ng-table-dynamic
指令。
例如:
<table ng-table-dynamic="tableParams with cols" show-filter="true" class="table table-bordered table-striped">
<tr ng-repeat="row in $data track by row.id">
<td ng-repeat="col in $columns">{{::row[col.field]}}</td>
</tr>
</table>
注意在指令声明中使用了特殊语法tablePrams
with
cols
。这里的 cols 是一个 $scope
变量,它必须遵循以下模式才能正常工作。
$scope.cols = [
{ title: 'ID', field: 'id', filter: { id : 'text' }, show: true, sortable: 'id' },
{ title: 'Installation', field: 'installationAt' },
...
];
标题和字段是必需的,而filter
、show
、sortable
取决于您的使用场景。
你可以玩这个 code pen
关于javascript - AngularJS - Ng-Table 不会解析标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33922527/