daniel-nagy / md-data-table

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

Colum sorting (md-order) doesnt work as expected #509

Closed mustafabereket closed 7 years ago

mustafabereket commented 7 years ago

Hey There,

I am pretty sure I am doing something wrong, but for some reason I couldnt find it.

Expected Behavior:

When you click sort icon next to the column name, it should sort the table in 'Ascending' order first. Click it second time, it should order 'Descending' order.

Behavior I get:

Doesnt sort at all.

Code I have:

Task ID Task Name Device Name Source Probs
{{item.task_id}} {{item.task_name}} {{item.device_name}} {{item.probs}}
        <md-table-pagination md-limit="tsCtrl.query2.limit" md-limit-options="[5,10,25]" md-page="tsCtrl.query2.page" md-total="{{tsCtrl.savedTasks.length}}" md-page-select></md-table-pagination>

Does anyone see what I might possibly be missing?

Thanks,

jansen07 commented 7 years ago

md-on-reorder -- you have to create a function that request JSON data from the server w/ paging and Sorting Capability in JSON format. the ordering takes place in server side. or just add Filter on the header.

mustafabereket commented 7 years ago

"you have to create a function that request JSON data from the server w/ paging and Sorting Capability in JSON format."

I can re-fill my array with same information, but what did you mean by "with paging and sorting capability"? if I am going to sort my array in the server side, what is the whole point using md-table's sorting functionality?

daniel-nagy commented 7 years ago

You need to pipe your repeater through orderBy.

<tr md-row ng-repeat="item in tsCtrl.savedTasks | orderBy: tsCtrl.query2.order | limitTo: tsCtrl.query2.limit: (tsCtrl.query2.page - 1) * tsCtrl.query2.limit" >

If you are pulling items down from the server in chunks (i.e. paginating on the server) then @jansen07 is right, you will need to utilize md-on-reorder and dispatch a query to the server to sort the items.

mustafabereket commented 7 years ago

Thank you so much @daniel-nagy ! this solves my problem. I appreciate it!