gpt4 book ai didi

javascript - 排序和过滤器不起作用 - Ngtable

转载 作者:行者123 更新时间:2023-11-30 11:39:20 26 4
gpt4 key购买 nike

我在开始使用 ngtables 时遇到了一些困难。现在,分页是正确的,但我无法进行排序和过滤。定义的初始排序顺序都不起作用有什么建议吗?谢谢

脚本

var app = angular.module('ruyapp', ['ngTable']);

app.controller('equipasCtrl', function ($scope, $filter, NgTableParams) {

var tamanho = $("#Tamanho").val();

$scope.init = function (equipasCT) {
$scope.equipas = equipasCT;
};

$scope.equipasTable = new NgTableParams({
page: 1,
sorting:{Nome: 'asc'},
count: $("#Npagina").val()
}, {
total: tamanho,
getData: function ($defer, params) {
$scope.data = params.sorting() ? $filter('orderBy')($scope.equipas, params.orderBy()) : $scope.equipas;
$scope.data = params.filter() ? $filter('filter')($scope.data, params.filter()) : $scope.data;
$scope.data = $scope.equipas.slice((params.page() - 1) * params.count(), params.page() * params.count());
$defer.resolve($scope.data);
}
});
});

查看

<div ng-app="ruyapp" ng-controller="equipasCtrl" ng-init="init(@Newtonsoft.Json.JsonConvert.SerializeObject(Model))">

<table class="table" ng-table="equipasTable" show-filter="true">
<tbody>
<tr ng-repeat="row in $data">

<td data-title="'Nome'" sortable="'Nome'" filter="{ 'Nome': 'text'}">
{{row.Nome}}
</td>
<td data-title="'Country'" sortable="'Country'" filter="{ 'Country': 'text'}">
{{row.Country}}
</td>

<td data-title="'Abreviatura'" sortable="'Abreviatura'" filter="{ 'Abreviatura': 'text'}">
{{row.Abreviatura}}
</td>
<td>
<a href="Equipas/Edit/{{row.EquipaID}}"> Editar</a> |
<a href="Equipas/Details/{{row.EquipaID}}"> Detalhes</a> |
<a href="Equipas/Delete/{{row.EquipaID}}"> Eliminar</a>
</td>
</tr>

</tbody>
</table>


</div>

View

最佳答案

这是一个工作示例。 http://codepen.io/mkl/pen/KWjbKV这就是我更改 getData 周围的代码以使排序和过滤工作的方式。

{
//total: $scope.data.length,
getData: function(params) {
var data = $scope.equipas;
data = params.filter() ? $filter('filter')(data, params.filter()) : data;
data = params.orderBy() ? $filter('orderBy')(data, params.orderBy()) : data;
params.total(data.length);
data = data.slice((params.page() - 1) * params.count(), params.page() * params.count());
return data;
}

关于javascript - 排序和过滤器不起作用 - Ngtable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43295974/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com