JD.
JD.

Reputation: 15551

How to get the selected item after filtering in angularjs?

I have the following:

    <table class="table table-striped">
            <thead>
            <tr>
                <th>Name</th>
                <th>Url</th>
                <th>Published</th>
                <th>Import</th>
            </tr>
            </thead>
            <tr ng-repeat="catalogObject in catalog | filter:catalogueSearchText |
                 orderBy:sortOrder:true"">
                <td>{{catalogObject.name}}</td>
                <td>{{catalogObject.url}}</td>
                <td>{{catalogObject.published}}</td>
                <td style="text-align:center">
                    <div class="btn btn-primary"
                  ng-click="ok(catalogObject.originalPosition)">&#10004;</div></td>
            </tr>
        </table>

I have created the originalPosition property so that once I have filtered my catalog I know exactly what position the selected object is in the catalog scoped list.

Is there a better way than creating this additional property on my collection using a more declarative approach?

So basically I need a way to get access to the selected item once the original list has been filtered and sorted (before I just used $index in ng-click = "ok($index") however this index does not correspond to the original position of the elements in my catalog list).

Upvotes: 0

Views: 199

Answers (1)

wvdz
wvdz

Reputation: 16651

You want to access the original object, but you already have this object!

All you have to do is make a small modification to your ok() function, so that it works for ok(catalogObject)

Upvotes: 1

Related Questions