2017-10-05 173 views
0

我正在嘗試使用角度數據表自定義搜索列 執行下面的腳本時顯示未捕獲錯誤列未定義顯示錯誤消息。角度數據表自定義列過濾器不工作

SCRIPT: 這是我的角度js代碼

(function (angular) { 
 
    'use strict'; 
 
    angular.module('datatablesSampleApp', ['datatables']). 
 
     controller('simpleCtrl', function ($scope, DTOptionsBuilder, DTColumnBuilder) { 
 
      $scope.data = [{ 
 
       "id": 860, 
 
       "firstName": "Superman", 
 
       "lastName": "Yoda" 
 
      }, { 
 
       "id": 870, 
 
       "firstName": "Foo", 
 
       "lastName": "Whateveryournameis" 
 
      }, { 
 
       "id": 590, 
 
       "firstName": "Toto", 
 
       "lastName": "Titi" 
 
      }]; 
 
      $scope.dtOptions = DTOptionsBuilder.newOptions().withPaginationType('full_numbers'); 
 
      $scope.searchData = function (searchText, index) { 
 
       $scope.table.column(index).search(searchText).draw(); 
 
      }; 
 
      $scope.$on('event:dataTableLoaded', function (event, loadedDT) { 
 
       $scope.table = loadedDT.DataTable; 
 
      }); 
 
      $scope.blockSorting = function($event){ 
 
       $event.preventDefault(); 
 
       $event.stopPropagation(); 
 
      } 
 
     }); 
 
})(angular);
**HTMl** 
 
I am creating a custom filter in angular js this is my html, 
 
<!DOCTYPE html> 
 
<html> 
 
    
 
    <head> 
 
      <link rel="stylesheet" href="style/jquery.dataTables.css" /> 
 
    </head> 
 
    
 
    <body ng-app="datatablesSampleApp"> 
 
<div ng-controller="simpleCtrl" class="code" style="width: 500px"> 
 
<table datatable="" dt-options="dtOptions" dt-columns="dtColumns"> 
 
<thead> 
 
<tr> 
 
<th>ID 
 
       <input type="text" ng-model="search.id" ng-change="searchData(search.id,0)" ng-click="blockSorting($event)" /></th> 
 
<th>FirstName 
 
       <input type="text" ng-model="search.firstName" ng-change="searchData(search.firstName,1)" ng-click="blockSorting($event)"/></th> 
 
<th>LastName</th> 
 
</tr> 
 
</thead> 
 
<tbody> 
 
<tr ng-repeat="person in data"> 
 
<td>{{ person.id }}</td> 
 
<td>{{ person.firstName }}</td> 
 
<td>{{ person.lastName }}</td> 
 
</tr> 
 
</tbody> 
 
</table> 
 
</div> 
 
<script src="script/jquery-1.10.1.min.js"></script> 
 
    <script src="script/jquery.dataTables.js"></script> 
 
    <script src="http://code.angularjs.org/1.2.15/angular.js"></script> 
 
    <script src="script/angular-resource.js"></script> 
 
    <script src="angular-datatables.min.js"></script> 
 
    <script src="script.js"></script> 
 
    </body> 
 
    
 
</html>

`過濾器不工作,也是我在控制檯中出現錯誤。 未捕獲錯誤列未定義顯示錯誤消息。

回答

0

$ scope.searchData =函數(SEARCHTEXT,索引){

var table = $('#DataTables_Table_0').DataTable(); 
    table.columns().every(function() { 
     var column = this; 
     table.column(index).search(searchText).draw(); 

    }); 
};