问题描述
我无法让“groupBy”工作。 我有一个从 $http 工厂返回的数据集。数据被传递到 $scope 'territoryReq' 变量。 数据集如下所示:
[{"Country":"Netherlands","Name":"firstName lastName","Phone":"+12345678","Mobile":"+987654321"},{"Country":"Netherlands","Name":"firstName2 lastName2","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>
这一切正常。没问题。 现在我想让结果按国家分组。最好能够单击国家/地区,然后取消隐藏具有正确国家/地区的行。 我正在查看 example of ng-table with grouping
的示例但我无法让它为我的数据工作..
在示例中,他们使用例如group in $groups
但我不知道 $groups 来自哪里?
无论如何,我希望有人能在正确的方向上帮助我...
谢谢!
解决方法
对于直接分组,groupBy
将对象属性作为参数。应该很简单
<tr class="ng-table-group" ng-repeat="entries in territoryReq | groupBy: 'Country'">
但这听起来更像是您想根据国家/地区等条件过滤列表。
我对此进行了模拟,以展示我认为您正在寻找的内容。请看看它是否有帮助...它通过表格标题进行排序并从动态国家/地区列表中过滤。