0

I'm starting AngularJS. I'm dynamically building a table with angular and I'm trying to add a filter to one of my columns.

Here the code I have in my controller :

$scope.columns = [
    {
        "alias":"alias1",
        "name":"name1",
        "type":"string"
    },
    {
        "alias":"alias2",
        "name":"name2",
        "type":"currency"
    }
];

$scope.data = [
    {
        "alias1": "value1",
        "alias2": "22489"
    },
    {
        "alias1": "value2",
        "alias2": "22489"
    },
    {
        "alias1": "value3",
        "alias2": "22489"
    },
];

And my table looks like this :

<table class="table table-hover">
    <thead>
        <tr>
            <th ng-repeat="c in columns" ng-click="sort(c.alias)">{{ c.name }}</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="result in results | filter:search | orderBy:sortKey:reverse">
            <td ng-repeat="c in columns">{{ result[c.alias] }}</td>
        </tr>
    </tbody>
</table>

What I'd like to do is to apply a filter to the <td> value based on the type of the column. Something like {{ result[c.alias] | c.type }} doesn't work...

Is it something that can be achieved by some formatting directive for example ?

Thanks for you help.

1 Answer 1

1

You mean this?:

app.filter('myfilter', function() {
    return function(input, param) {
        //do whatever
    }
})

{{ result[c.alias] | myfilter:c.type }}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.