2016-03-03 27 views
1

使用AngularJS和SmartTable ...... 我有當過濾器表內應用的正常工作持久狀態。 我加入其搜索的所有列的自定義搜索欄。 這也適用。 然而這種應用過濾器沒有被我的持久狀態指令舉行。 我相信它的一個範圍內的問題,但似乎無法行中的兩個,以滿足。AngularJS SmartTable持久狀態不與自定義搜索舉行(範圍問題?)

這裏是一個Plunker http://plnkr.co/edit/2qt7f6NxKH2blJ5GudNl?p=preview

是我寫的範圍不正確?

這裏是我的自定義搜索指令

// Text Search for all columns in stTable 
// USAGE: <input type="text" ng-model="queryAllColumns"/> 
// There HAS TO BE a way to implement this into the stPersist 
.directive('searchWatchModel',function(){ 
    return { 
    require:'^stTable', 
    scope:{ 
     searchWatchModel:'=' 
    }, 
    link:function(scope, ele, attr, ctrl){ 
     var table=ctrl; 

     scope.$watch('searchWatchModel',function(val){ 
     ctrl.search(val); 
     }); 

    } 
    }; 
}) 

這裏是我的持久表格指令

// Create a Persistant Table Display 
// Allows you to close the browser and return with filters still applied 
// USAGE: on the st-able ADD: st-persist="myTable" <--myTable can be anything 
.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(); 

      } 

     } 
    }; 
}) 

回答

1

我相信已經有一個「全局搜索」提供智能表。

<input st-search placeholder="global search" class="input-sm form-control" type="search"/> 

那麼爲什麼你必須創建自己的自定義搜索?也許我錯過了一些東西。

順便說一句,你應該油門/延遲添加到您的stPersist指令,以避免不必要的localStorage setItem。

+0

這只是一個原型「確保基礎工作第一」。 Global不會很好地搜索日期。我相對較新的角度...任何關於stPersist上的油門/延遲研究的建議? ...我不確定我會怎麼寫?你是指輸入提前搜索......只要我鍵入「一個......」它緩存到本地存儲? ...我在400ms的st搜索中看到了一個內置延遲......這就是你指的是什麼? – Acts7Seven