Michael W
Michael W

Reputation: 301

How to use orderBy for a property of an array of arrays in ng-repeat

Is there a way to order the following example data set by the value property or a specific array index?:

var rows = [
    [
        {
            value: 'hello',
            label: 'world'
        },
        {
            value: 'hello1',
            label: 'world1'
        },
        {
            value: 'hello2',
            label: 'world2'
        }
    ],
    [
        {
            value: 'asd',
            label: 'jkl'
        },
        {
            value: 'asd1',
            label: 'jkl1'
        },
        {
            value: 'asd2',
            label: 'jkl2'
        }
    ]
];

I tried this repeat statement:

ng-repeat="row in rows | orderBy:'-[1].value'"

It's not throwing an error but it also doesn't do the ordering.

Upvotes: 0

Views: 1208

Answers (1)

Jaanus
Jaanus

Reputation: 16541

Change the ng-repeat this this. This will order rows by the values of first column. this represents the row.

ng-repeat="row in rows | orderBy:'this[0].value'"

Upvotes: 2

Related Questions