2016-08-25 5 views
1

私はサーバにtableStateを格納する必要があります。そのため、ユーザが後でログインしたときに、ソートとフィルタリングがすべて適用されたままの状態を正確に表示できます。 stPipe関数をオーバーライドせずに現在のtableStateにアクセスできる方法はありますか?AngularJSスマートテーブル:stPipe関数をオーバーライドせずにtableStateにアクセスできる方法はありますか?

答えて

0

テーブル状態を保存するのに便利なplunkrが見つかりました。私は、サーバー上の状態を保存の代わりのlocalStorage

http://plnkr.co/edit/ekwiNt?p=info

.directive('stPersist', function() { 
     return { 
      require: '^stTable', 
      link: function (scope, element, attr, ctrl) { 
       var nameSpace = attr.stPersist; 

       //save the table state every time it changes 
       scope.$watch(function() { 
        return ctrl.tableState(); 
       }, function (newValue, oldValue) { 
        if (newValue !== oldValue) { 
         localStorage.setItem(nameSpace, JSON.stringify(newValue)); 
        } 
       }, true); 

       //fetch the table state when the directive is loaded 
       if (localStorage.getItem(nameSpace)) { 
        var savedState = JSON.parse(localStorage.getItem(nameSpace)); 
        var tableState = ctrl.tableState(); 

        angular.extend(tableState, savedState); 
        ctrl.pipe(); 

       } 

      } 
     }; 
    });; 
するために、これを拡張することができるはず
関連する問題