使用 NgTable 从输入添加新的自定义过滤器

Add new custom filter from input with NgTable

我有一个输入,用户可以在其中输入他想要的 "preGEAS"。 但是,如果我尝试通过 $scope 变量添加具有此值的过滤器,则不会发生任何事情。

我尝试了 2 种解决方案:直接在声明 ngTableParams 中,另一种在 applyPreGEASFilter 函数中。

$scope.myData = [{  (properties) ... , preGEAS: "TEST VALUE" }, ... ];
$scope.filtrePreGEAS = "";

var initialParams = {   count : 10, filter: { preGEAS: $scope.filtrePreGEAS }   }; // initial page size

                            var initialSettings = {
                                counts : [],
                                paginationMaxBlocks : 13,
                                paginationMinBlocks : 2,
                                dataset : $scope.myData
                            };
                            $scope.myTable = new ngTableParams(initialParams, initialSettings);

//                      $scope.applyPreGEASFilter = function() {
//                          console.log("filter applied");
//                          $scope.tableRcdCalendrier.filter($scope.filtrePreGEAS);
//                      }

HTML


        <select class="form-control overloadDC" title="choose" ng-model="filtrePreGEAS" ng-change="applyPreGEASFilter()"
                ng-options="item for item in LISTE_PAR_GESTION_PREGEAS_DOMAINE">
<!--                <option value="null"></option>   -->                                                                
        </select>

<table id="idTable" ng-table="myTable" show-filter="true" class="table table-bordered table-condensed calAffairesImp" style="width: 100%">                              
            <tr>
                <th ng-repeat="header in Headers" class="rotated-text" ng-mouseover="mouseOver(header, $index)" ng-mouseleave="mouseOver('', null)" ng-class="{highlighted: (hoveredCol == $index)}">
                <div><span ng-bind-html="trust(header)"></span></div></th>
            </tr>

            <tr ng-repeat="row in $data"  > <!--   ::: ng-if="filtrePreGEAS == '' || row.preGEAS == filtrePreGEAS" :::  | filter: { preGEAS : filtrePreGEAS } -->
                <td ng-repeat="(key, value) in row" 
                    ng-if="key != 'preGEAS' && key != 'indexUnique'"
                    ng-mouseover="mouseOver(value, $index)" 
                    ng-mouseleave="mouseOver('', null)" 
                    ng-class="{highlighted: (hoveredCol == $index)}" 
                    data-title="key" 
                    filter="" sortable="" 
                    style="word-wrap: break-word; width: 5%;">
                    <div style="word-wrap: break-word; width: 100%; overflow: hidden;">
                        <!-- ng-if with inputs and selects -->
                    </div>
                </td>

            </tr>
        </table>

我在 Google 上看到了 GetData 函数,但我不想改变我的观点并导致回归。

我找到了解决方案:filtrePreGEAS 是字符串而不是对象。

$scope.filtrePreGEAS = { nameKey: "" };

取消注释 applyPreGEASFilter(),现在一切正常。