ng-table:列过滤 [英] ng-table : filter on column
问题描述
我正在使用ng-table,我想过滤我的列.它可以处理简单的数据.
I am using ng-table and I want to filter my columns. It works with a simple data.
<table ng-table="tableParams" show-filter="true" class="table table-striped table-bordered table-hover" id="dynamic-table">
<tr ng-repeat="consultant in $data">
<td class="text-center" data-title="'Ville résidence'" filter="{ 'villeResidence': 'text' }">{{consultant.villeResidence}}</td>
<td class="text-center" data-title="'Contrat'" filter="{ 'typeContrat.contrat': 'text' }" >
<span ng-repeat="typeContrat in consultant.typeContrats">
<a class="form-control-static" ui-sref="type-contrat-detail({id: {{typeContrat.id}}})">{{typeContrat.contrat}}</a>{{$last ? '' : ', '}}
<span>
</td>
</tr>
</table>
但是具有更复杂的列(在此为"contrat"),我不知道该怎么做.如果有人知道...
But with a more complexe column(here : "contrat") I don't know how to do that. If anyone knows...
[更新]
<td class="text-center" data-title="'Contrat'" filter="{ 'typeContrat.contrat': 'text' }" data-title-text="Contrat">
<!-- ngRepeat: typeContrat in consultant.typeContrats -->
<span ng-repeat="typeContrat in consultant.typeContrats" class="ng-binding ng-scope">
<a class="form-control-static ng-binding" ui-sref="type-contrat-detail({id: 1})" href="#/type-contrat/1">CDI</a>,
<span>
</span>
</span>
<!-- end ngRepeat: typeContrat in consultant.typeContrats -->
<span ng-repeat="typeContrat in consultant.typeContrats" class="ng-binding ng-scope">
<a class="form-control-static ng-binding" ui-sref="type-contrat-detail({id: 2})" href="#/type-contrat/2">Freelance</a>,
<span></span>
</span>
<!-- end ngRepeat: typeContrat in consultant.typeContrats -->
<span ng-repeat="typeContrat in consultant.typeContrats" class="ng-binding ng-scope">
<a class="form-control-static ng-binding" ui-sref="type-contrat-detail({id: 3})" href="#/type-contrat/3">Portage</a>
<span></span>
</span><!-- end ngRepeat: typeContrat in consultant.typeContrats -->
</td>
推荐答案
As mentioned here and as I looked around in the docs, I concluded ng-table is not well suited for nested models.
一种解决方法是根据 contats
的数组数据创建一个属性,然后对其进行过滤.因此,对于每个 consultant
,我添加了一个属性 contracts
,其中包含其 typeContrats.contats
的连接字符串:
A workaround could be to create a property based on your array data of contats
and then filter by it.
So, for each consultant
, I added a property contracts
which contains the concatenated string of its typeContrats.contats
:
_.forEach(consultantData, function(value) {
var contrats = _.map(value.typeContrats, 'contrat');
value.contrats = _.join(contrats, ', ');
});
然后在HTML中:
<td class="text-center" data-title="'Contrat'" filter="{ 'contrats': 'text' }">
以下是带有示例的小提琴.
我希望这是您要实现的目标.
I hope this is what you were trying to achieve.
这篇关于ng-table:列过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!