简体   繁体   中英

Sort a table column where the header has whitspace

I have an angular based table which I would like to sort by one of the columns

If I sort by the column Reference this line works

<tr ng-repeat="row in documentaryCreditsTable.rows | orderBy:'-Reference'">

However I would like to sort by a column named 'Expiry date' and I'm assuming that since this column has a space I'm getting the following error:

 <tr ng-repeat="row in documentaryCreditsTable.rows | orderBy:'-Expiry date'">

Error: [$parse:syntax] Syntax Error: Token 'date' is an unexpected token at column 8 of the expression [Expiry date] starting at [date].

Any idea how to work around that as this String is what is presented to the user on the screen and I would like to keep the whitespace.

Controller:

var sortBy = 'Expiry date';
$scope.predicate = function(val) {
  return -val[sortBy];
}

View:

<tr ng-repeat="row in documentaryCreditsTable.rows | orderBy:predicate">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM