智能 table st-search 将不起作用

Smart table st-search won't work

我通过 ng-include 在我的页面中实现了智能 table,但 st-search 不起作用。这是我的代码:

Table

 <div class="horizontal-scroll" ng-controller="SmartTableController">
  <div class="form-group select-page-size-wrap ">
    <label>Rows on page
      <select class="form-control selectpicker show-tick" title="Rows on page" selectpicker
              ng-model="smartTablePageSize" ng-options="i for i in [5,10,15,20,25]">
      </select>
    </label>
  </div>
  <table class="table" st-table="displayedData" st-safe-src="smartTableData" >
    <thead>
    <tr class="sortable ">
      <th class="table-id" st-sort="id" st-sort-default="true">#</th>
      <th st-sort="firstname">Prénom</th>
      <th st-sort="lastname">Nom</th>
      <th st-sort="role">Rôle</th>
      <th st-sort="email">Email</th>
      <th st-sort="chargeRate">Taux de charge</th>
    </tr>
    <tr>
      <th></th>
      <th><input st-search="firstname" placeholder="Chercher Prénom" class="input-sm form-control search-input"
                 type="search"/></th>
      <th><input st-search="lastname" placeholder="Chercher Nom" class="input-sm form-control search-input"
                 type="search"/></th>
      <th><input st-search="role" placeholder="Chercher Rôle" class="input-sm form-control search-input"
                 type="search"/></th>
      <th><input st-search="email" placeholder="Chercher Email" class="input-sm form-control search-input" type="search"/>
      </th>
      <th><input st-search="chargeRate" placeholder="Chercher Taux de charge" class="input-sm form-control search-input" type="search"/>
      </th>
    </tr>
    </thead>
    <tbody>
    <tr ng-repeat="item in displayedData">
      <td class="table-id">{{item.id}}</td>
      <td>{{item.firstname}}</td>
      <td>{{item.lastname}}</td>
      <td>{{item.role[0].name}}</td>
      <td><a class="email-link" ng-href="mailto:{{item.email}}">{{item.email}}</a></td>
      <td>{{item.chargeRate}}</td>
    </tr>
    </tbody>
    <tfoot>
    <tr>
      <td colspan="6" class="text-center">
        <div st-pagination="" st-items-by-page="smartTablePageSize" st-displayed-pages="5"></div>
      </td>
    </tr>
    </tfoot>
  </table>
</div>

然后我从其他应用程序获取数据,这是我的控制器:

angular.module('BlurAdmin.pages.users')
.controller('SmartTableController',SmartTableController);

function SmartTableController ($log, $scope, smartTableFactory) {

$scope.smartTableData = [];
$scope.selectedUsers = {};
$scope.smartTablePageSize = 10;


/**
 * Get Smart Table data
 */
$scope.getSmartTableData = function () {
    smartTableFactory.getSmartTableData()
            .success(function (data) {
                $scope.smartTableData = data;
                $scope.displayedData = angular.copy($scope.smartTableData);
                console.log(" Data : " , data);
//Edit 
    $scope.displayedData = $scope.smartTableData;
            })
            .error(function (data, status) {

                $scope.addMessage = "Erreur data : " + data + ' ' + status;
                $log.log(data.error + '' + status);
            });
    };

$scope.getSmartTableData();

}

我的服务工作正常,我正在获取数据,而且它确实显示在 table 上,我只是无法搜索。

如有任何帮助,我们将不胜感激。谢谢

我试过了。结论 您的代码可能会发生 $http 错误不聪明 table 一个。 JSFiddle
当我使用这些 JSON 数据时,我可以过滤除 'role' 列之外的所有列。

   $scope.smartTableData =
        [
        { firstname: 1, lastname: 'aaaa', role: [{ name: 'employee1' }], chargeRate: 10, email: 'aaaa@' },
        { firstname: 2, lastname: 'bbbb', role: [{ name: 'employee2' }], chargeRate: 20, email: 'bbbb@' },
        { firstname: 3, lastname: 'cccc', role: [{ name: 'employee3' }], chargeRate: 30, email: 'cccc@' },
        { firstname: 4, lastname: 'dddd', role: [{ name: 'employee4' }], chargeRate: 40, email: 'dddd@' }
        ];

请确认您的数据JSON格式是否正确。

在 'role' 列中,您应该这样编码。
好的<input st-search="role.name"
不对 <input st-search="role"

而且我认为您不必编写这部分代码,因为它没有必要。

   $scope.displayedData = angular.copy($scope.smartTableData);
   $scope.displayedData = $scope.smartTableData;