How can I reset the sort order after a row has been selected?

135 views Asked by At

I am using smart-table to show a list of possible matches. When a row is selected, it then shows the next list of possibilities.

By default, the table is sorted by a "ranking" column. Its possible for the user to click a different header and have it sorted by that column instead.

After a row has been selected, and the next results are loaded, is it possible to reset the st-sort back to what it was initially? I've searched the github for terms like "reset sort" and I haven't been successful.

1

There are 1 answers

0
Lewis Cianci On

I worked it out.

Use this directive:

  ng.module('smart-table')
        .directive('stResetSearchOrder',
            [
                'stConfig', function(stConfig) {
                    return {
                        restrict: 'A',
                        require: '^stTable',
                        scope: {
                            row: '=stSelectRow',
                            defaultOrderBy: '<',
                            defaultReverseOrder: '@'
                        },
                        link: function(scope, element, attr, ctrl) {
                            element.bind('click',
                                function () {
                                    var orderable = scope.defaultOrderBy;
                                    ctrl.sortBy(orderable, scope.defaultReverseOrder != "true");
                                });
                        }
                    };
                }
            ]);

Then add these attributes on your tr in your ng-repeat

 st-reset-search-order default-order-by="the name of your property" default-reverse-order="false"

In my case I'm sorting by a function, and it works well.