且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ngtable服务器端分页

更新时间:2023-11-27 22:26:10

您没有看到分页按钮,因为你的get()可能会返回10,因为在服务器端,如果你的具有rangeStart,RANGESTOP限制计数返回10个结果出来,共10件没有什么可分页。

You don't see pagination buttons because your get() probably returns 10 for count because of your "rangeStart", "rangeStop" limit on server side and if you return 10 results out of 10 total there is nothing to paginate.

您可以返回10个结果,每个请求,但params.total应该永远是所有结果计数。

You can return 10 results per request but params.total should always be count of all results.

反正你不需要2的get()调用时,你可以在一个这样的回报是:D

Anyway you don't need 2 get() calls when you can return it in one like this :D

{
    "results": [
        {
            "id": "1437",
            "task_started_at": "2014-06-09 12:25:25",
            "task_finished_at": "2014-06-09 12:25:25"
        },
        {
            "id": "1436",
            "task_started_at": "2014-06-09 12:26:31",
            "task_finished_at": "2014-06-09 12:26:31"
        }
    ],
    "total": 1027
}

和你code可能是这样的:

And you code could look like this:

params.total(data.total);
$defer.resolve(data.results);

,你也不必总,因为你会得到它从seerver所以删除:

And also you don't need total because you will get it from seerver so remove:

total: 0;

Finaly您code与2的get()调用可能看起来是这样的:

Finaly your code with 2 get() calls could look something like this:

this.tableParams = new ngTableParams({
        page: 1,
        count: 10
    }, {
        getData: function($defer, params) {
            $http.get('/app/api/period', {params: {
                pageNumber:params.page() - 1,
                rangeStart:rangeStart,
                rangeStop:rangeStop}})
                .success(function(data, status) {

                   params.total($http.get('/app/api/period/count'));

                   $defer.resolve(data);
                });
        }
    });

其中, $ http.get('/ APP / API /时间/计数')返回记录总数像 1234

好运气