Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current sorted column in smart-table

I have st-sort directive on all columns in my smart-table. When an user clicks certain column how can I get current sorted column? Is there some trick or do I have to listen to the click event on those column headers?

like image 800
yalkris Avatar asked Dec 01 '25 03:12

yalkris


2 Answers

you can use the directive st-pipe, this function will be called for sorting, paginating or filtering events.

<table st-table="displayedCollection" st-safe-src="rowCollection" st-pipe="customPipe">

$scope.customPipe = function(tableState){
   console.log(tableState.sort);
}
like image 119
Rafael Zeffa Avatar answered Dec 02 '25 18:12

Rafael Zeffa


I think the technique which will give you the best control will be to create a plugin which will watch changes in the table state and will call a provided callback whenever a change is detected (in your case you will pay particular attention to the "sort" namespace of the table state

module.directive('stSentinel',function (){
   return{
      require:'^stTable',
      scope:{
        onChange:'&stSentinel'
      },
      link:function(scope, element, attr, stTable){
        scope.$watch(function(){
          return stTable.tableState();
        },function (newVal){
          scope.onChange(newVal);
        },
        true)}
     }
   };
});

which you can use in your markup

<table st-table="foo" st-sentinel="myCtrl.applyChange(tableState)"> ... </table>

Your controller will define the applyChange method to react the changes

like image 35
laurent Avatar answered Dec 02 '25 19:12

laurent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!