daniel-nagy / md-data-table

Material Design Data Table for Angular Material
MIT License
1.9k stars 520 forks source link

Multiple parameter ordering #648

Closed basklein closed 6 years ago

basklein commented 6 years ago

I am looking for a way to orderBy using multiple parameters when clicking on one column. I am not sorting by multiple different columns at the same time, just one with multiple values in it.

It is possible to orderBy an array when using ng-repeat normally like this:

<div ng-repeat="item in items | orderBy: ['one', 'two']">

However, it doesn't appear to be possible to do this with the way ordering is set up in the table at the moment. Right now, if I try to use this syntax, I get an error because AngularJS expressions can't have a comma in them. So I tried passing the array to the scope via a controller, but then it only sorts based on the first parameter. I did however figure out that using only one parameter inside an array works without any issues. As such I think the solution may lie in converting all values received in md-order-by to an array and applying things like the - for swapping directions to each element seperately.

I'm trying to figure out how to solve this problem myself, but I am quite new to web development in general, so I'm having a bit of trouble and could use some assistance.

tl;dr: I want be to able to write md-order-by="['one', 'two']" and have it work.

basklein commented 6 years ago

There was a mistake in my own code. After examining the demo app and comparing it to my own, I realized I forgot to put in quotation marks around the array and a comma would break the code entirely.