角度 NgTable 分页不起作用

Angular NgTable pagination doesn't work

本文关键字:不起作用 分页 NgTable 角度      更新时间:2023-09-26

我试图弄清楚我做错了什么,但找不到示例使用新版本的 NgTable

我可以从 NgTable 获取重新加载和数组,但我的分页不起作用

由于某些内容已被弃用,因此找不到处理新更改的方法。

这是与ng-table v 0.8.3

$scope.listaDetalleFactura = function () {
                var idFacturaDetalle = $routeParams.idFactura;
                $scope.detalleFacturas = "";
                $promesa = facturaService.getDetalleFacturaList(idFacturaDetalle);
                $promesa.then(function (datos) {
                    $scope.detalleFacturas = datos.data;
                    var data = datos.data;
                    $scope.tableParams = new NgTableParams({
                        page: 1,
                        count: 5
                    }, {
                        total: data.length,
                        getData: function (params) {
                            data = $scope.detalleFacturas;
                            params.total(data.length);
                            if (params.total() <= ((params.page() - 1) * params.count())) {
                                params.page(1);
                            }
                            return data.slice((params.page() - 1) * params.count(), params.page() * params.count());
                        }});
                });
            };

我的桌子:

<table ng-table="tableParams" style="margin-top: 10px;" 
                                       class="table-condensed table-bordered table-striped"                                   
                                       data-ng-init="listaDetalleFactura()"
                                       >
                                    <thead>
                                        <tr>
                                            <th style="width: 40px; text-align: center;">Id</th>
                                            <th style="width: 300px;">Descripcion</th>
                                            <th style="width: 30px; text-align: center;">Cantidad</th>
                                            <th style="width: 150px; text-align: center;">Precio por Unidad</th>
                                            <th style="width: 50px; text-align: center;">Descuento</th>
                                            <th style="width: 50px; text-align: center;">Total</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr ng-repeat="detalleFactura in detalleFacturas">
                                            <td style="text-align: center;">{{detalleFactura.idDetalleFactura}}</td>
                                            <td>{{detalleFactura.producto.descripcion}}</td>
                                            <td style="width: 30px; text-align: center;">{{detalleFactura.cantidadDetalle}}</td>
                                            <td style="width: 150px; text-align: center;">{{detalleFactura.producto.precioVenta}}</td>
                                            <td style="width: 50px; text-align: center;">{{detalleFactura.descuentoDetalle}}</td>
                                            <td style="width: 50px; text-align: center;">{{detalleFactura.totalDetalle}}</td>
                                        </tr>
                                    </tbody>
                                </table>

好吧,我感觉很愚蠢,对不起浪费你的时间...希望有一天这会对某人有所帮助......

我的错误在于ng-repeat而不是detalleFacturas我应该使用$data

<tbody>
                                    <tr ng-repeat="detalleFactura in $data">
                                        <td style="text-align: center;">{{detalleFactura.idDetalleFactura}}</td>
                                        <td>{{detalleFactura.producto.descripcion}}</td>
                                        <td style="width: 30px; text-align: center;">{{detalleFactura.cantidadDetalle}}</td>
                                        <td style="width: 150px; text-align: center;">${{detalleFactura.producto.precioVenta}}</td>
                                        <td style="width: 50px; text-align: center;">{{detalleFactura.descuentoDetalle}}</td>
                                        <td style="width: 50px; text-align: center;">${{detalleFactura.totalDetalle}}</td>
                                    </tr>
                                </tbody>