JQuery 数据表。如何以编程方式更改当前页面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16496054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JQuery Datatables. How can I change the current page programmatically?
提问by code511788465541441
I have pagination on my table. I want go back back to the first page whenever a function is called. How can I do that?
我的桌子上有分页。每当调用函数时,我都想返回第一页。我怎样才能做到这一点?
回答by carrabino
from the docs: http://datatables.net/ref#fnPageChange
来自文档:http: //datatables.net/ref#fnPageChange
$(document).ready(function() {
var oTable = $('#example').dataTable();
oTable.fnPageChange( 'first' );
} );
回答by Mohammad Adil
var oTable = $('#example').dataTable();
oTable.fnPageChange( 'first' );
OR
或者
oTable.fnPageChange( 0 );
回答by deepika
In the Datatables version 10 there is a page() function which is used to change the page.
在 Datatables 版本 10 中,有一个 page() 函数用于更改页面。
For eg. table.page('first');
will jump to first page
例如。table.page('first');
会跳到第一页
table.page(pageNumber);
will jump to the corresponding page where pageNumber
is indexed from 0.
table.page(pageNumber);
将跳转到pageNumber
从 0 开始索引的相应页面。
Reference: http://datatables.net/reference/api/page()
回答by Pablo Salazar
This seems to work for me:
这似乎对我有用:
table.page(pageNumber).draw(false);
This works with pagination where pageNumber
is the index of the page.
这适用于分页,其中pageNumber
是页面的索引。