I've got a list of invoices in ng-table and would like to be able to filter on a nested attribute. The json looks like this;
[
{
id: 1,
date: "20/03/2014",
no: "1",
client: {
fullname: "ABC Catering"
}
}
]
My view look like this
<table ng-table="tableParams" show-filter="true" class="table">
<tr class='listing' ng-repeat="invoice in $data">
<td data-title="'Invoice No.'" sortable="'no'" filter="{'no':'text'}">
{{invoice.no}}
</td>
<td data-title="'Date'" sortable="'date'" filter="{'date':'text'}">
{{invoice.date}}
</td>
<td data-title="'Client'" sortable="'client.fullname'" filter="{'client.fullname':'text'}">
{{invoice.client.fullname}}
</td>
<td>
<a href="/api#/invoices/{{invoice.id}}">Show</a>
<a href="/api#/invoices/{{invoice.id}}/edit">Edit</a>
<a href="" ng-confirm-click="destroy(invoice.id)">Delete</a>
</td>
</tr>
</table>
I would like to get the filtering working for client.fullname. How do I filter on nested attributes?
Update
I've found a work around where I just put the nested field into a non-nested JSON element, in the above example I create a JSON['client_name'] element and assign it to client.fullname within the rails model. Then the filter works as it's not nested.
Still looking for a way in which I could do without this work around.
ng-table
) would be to supply a custom comparator for filter, such that it compares based on yourclient.fullname
field. Here's a quick and dirty example I hacked up based on your supplied code - jsfiddle.net/hRdu4 – PenningtontableParams
? following the example of filtering on the ngtable webpage, filtering on nested attributes seems to work fine – Honeymoon