【发布时间】:2020-08-13 16:04:10
【问题描述】:
我正在使用制表符,我需要添加输入框,将您带到所需的页面。 如果您有 10 页并且想要转到第 9 页,您只需输入 9 并按 Enter。 此功能在 DataTables 中可用,这里是 example 那么如何用 Tabulator 做到这一点?谢谢你
【问题讨论】:
标签: javascript tabulator
我正在使用制表符,我需要添加输入框,将您带到所需的页面。 如果您有 10 页并且想要转到第 9 页,您只需输入 9 并按 Enter。 此功能在 DataTables 中可用,这里是 example 那么如何用 Tabulator 做到这一点?谢谢你
【问题讨论】:
标签: javascript tabulator
http://tabulator.info/docs/4.6/page#manage
您需要使用 table.setPage(x) 函数,其中 table 是您的 Tabulator 实例,x 是您要转到的页码。
下面是一个示例,说明事件侦听器函数在您的一个元素上的外观。
function pageListener(event){
if (isNaN(event.target.value)){
// We don't want anything that isn't a number.
return;
}
// Assuming that 'table' is a variable containing the
// Tabulator instance
table.setPage(Number(event.target.value));
}
【讨论】:
根据@nrayburn-tech 的回答,我修改了一些内容以使输入框显示在制表符页脚中。
//CSS
#test {
color:black;
text-align: center;
position:center;
}
.jumpTo{
width:30px;
height:10px;
}
//JS
$(".tabulator-footer").append("<div id='test'><input class='jumpTo' title='insert number to jump to a page'></input></div>");
document.getElementById("test").addEventListener('change', (event) => {
if (isNaN(event.target.value)) {
return;
}
tabulator_table.setPage(Number(event.target.value));
})
非常感谢
【讨论】: