angularjs NgTable ng-repeat groupby with show/hide



我无法使"groupBy"工作。我有一个从$http工厂返回的数据集。数据被传递到$scope"territoryReq"变量。数据集看起来像:

[{"Country":"Netherlands","Name":"firstName lastName","Phone":"+12345678","Mobile":"+987654321"},{"Country":"Netherlands","Name":"firstName2 lastName2","Phone":"+12345678","Mobile":"+987654321"}]

我有一个简单的数据"转储"使用:

<div>
<table ng-table="" class="table table-condensed table-bordered table-hover">
<tr class="ng-table-group" ng-repeat="entries in territoryReq">
<td>
{{entries.Country}}
</td>
<td>
{{entries.Name}}
</td>
<td>
{{entries.Phone}}
</td>
<td>
{{entries.Mobile}}
</td>
</tr>
</table>
</div>

这一切都在起作用。没问题。现在我想把结果按国家分组。最好是能够点击国家,然后取消隐藏具有正确国家的行。我在看ng表的例子和分组

但我无法让它为我的数据工作。。在这个例子中,他们使用例如group in $groups,但我不知道$groups来自哪里?不管怎样,我希望有人能在正确的方向上帮助我。。。

谢谢!

对于直接分组,groupBy将对象属性作为参数。它应该像一样简单

<tr class="ng-table-group" ng-repeat="entries in territoryReq | groupBy: 'Country'">

但这听起来更像是你想根据国家等标准筛选列表。

我模仿了这个来展示我认为你在寻找什么。请看一下,看看它是否有帮助。。。它通过表格标题进行排序,并从国家的动态列表中进行筛选。

https://stackblitz.com/edit/angularjs-yvxdrd

最新更新