如何覆盖 jquery 数据表 API 的脚本?
How to override scripts of jquery datatable API?
我正在开发 codeigniter,我已经在我的页面中实现了 jquery 数据table api。一切正常。如您所知,默认情况下,api 会在 table 上方为我们提供一个下拉菜单,我们可以在其中 select 没有要显示的记录,而且我们还具有搜索功能。现在,我想要的是,当用户向搜索框输入内容并且 table 显示搜索结果时。我想一次显示所有记录,而不是有限的结果。我该怎么做?
https://datatables.net/examples/advanced_init/length_menu.html
It is possible to easily customise the options shown in the length
menu (by default at the top left of the table) using the lengthMenu
initialisation option.
$(document).ready(function() {
$('#example').DataTable( {
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
} );
} );
google 的第一个结果:
How to show all rows by default in JQuery DataTable :
你需要
- 在
lengthMenu
中包含一个 -1
值,因此所有行都被选择 table
- 过滤table时,即广播
search.dt
时,选择lengthMenus -1
选项,触发change
事件
- 在 dataTable 对象上设置一个标志以防止事件被反复触发
示例:
var table = $('#example').DataTable({
lengthMenu: [[10, -1], [10, "All"]]
})
$('#example').on('search.dt', function(e, api) {
if (!api._allForced) {
$('.dataTables_length select option[value=-1]').prop('selected', true);
$('.dataTables_length select').change();
api._allForced = true
}
})
我正在开发 codeigniter,我已经在我的页面中实现了 jquery 数据table api。一切正常。如您所知,默认情况下,api 会在 table 上方为我们提供一个下拉菜单,我们可以在其中 select 没有要显示的记录,而且我们还具有搜索功能。现在,我想要的是,当用户向搜索框输入内容并且 table 显示搜索结果时。我想一次显示所有记录,而不是有限的结果。我该怎么做?
https://datatables.net/examples/advanced_init/length_menu.html
It is possible to easily customise the options shown in the length menu (by default at the top left of the table) using the lengthMenu initialisation option.
$(document).ready(function() {
$('#example').DataTable( {
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
} );
} );
google 的第一个结果:
How to show all rows by default in JQuery DataTable :
你需要
- 在
lengthMenu
中包含一个-1
值,因此所有行都被选择 table - 过滤table时,即广播
search.dt
时,选择lengthMenus-1
选项,触发change
事件 - 在 dataTable 对象上设置一个标志以防止事件被反复触发
示例:
var table = $('#example').DataTable({
lengthMenu: [[10, -1], [10, "All"]]
})
$('#example').on('search.dt', function(e, api) {
if (!api._allForced) {
$('.dataTables_length select option[value=-1]').prop('selected', true);
$('.dataTables_length select').change();
api._allForced = true
}
})