我在同一页面上有两个dataTables,例如以下示例: https://datatables.net/examples/basic_init/multiple_tables.html
直到没有问题..
它具有许多共同的参数,例如按钮或语言
$('table').DataTable({
language: {
search: "",
searchPlaceholder: "Search ...",
sLengthMenu:"_MENU_",
sInfo:"_TOTAL_ elmt",
infoFiltered: "",
sInfoEmpty: "0 elmt",
"oPaginate": {
"sPrevious": "<",
"sNext": ">"
}
}
});
但是,我希望给他们提供不同的pageLength
大小和不同的尝试,
我该怎么办?
知道第一个表的 ID 为table-one
,第二个表的 ID 为table-two
答案 0 :(得分:1)
执行以下操作:
// create an object with your settings for the first table
var dataTableOptions = {
language: {
search: "",
searchPlaceholder: "Search ...",
sLengthMenu:"_MENU_",
sInfo:"_TOTAL_ elmt",
infoFiltered: "",
sInfoEmpty: "0 elmt",
"oPaginate": {
"sPrevious": "<",
"sNext": ">"
}
}
};
// initialize that table
$('#table1').DataTable(dataTableOptions);
// modify whatever settings you need to in the object you created
dataTableOptions.language.sLengthMenu = "some new value";
// use the modified object to initialize the second table
$('#table2').DataTable(dataTableOptions);