选择Jquery Datatables中的所有行 [英] Select All rows in Jquery Datatables
问题描述
复选框也可以做,但是如何获取选定的值。
以下是单次和多次选择的代码。
var oTable = $(#示例)。dataTable();
$('#example tbody')。on('click','tr',function(){
$(this).toggleClass('selected');
});
在按钮提交上获取所选值的代码
var row = oTable.rows('。selected')。
var jsonArr =[;
if(row!= null&& row.length){
for(var i = 0; i< row.length; i ++){
var row1 = row [i]; //这将给我一行详细信息
// row1 [0]将给我列详细信息
jsonArr = jsonArr +{\ID\:+ row1 [0] + },
}
jsonArr = jsonArr +];
可能会帮助你的是TableTools扩展名。有一个示例,带有select_all和select_none按钮,这些按钮适用于所有页面。 / p>
一个默认限制是select_all将忽略当前的过滤,但是使用下面的代码很容易解决。为fnSelectAll提供true参数将启用过滤器感知选择。
tableTools:{
sRowSelect:'multi' ,
aButtons:[
{
sExtends:'select_all',
sButtonText:'Select All',
fnClick:function(nButton,oConfig,oFlash){
TableTools.fnGetInstance('example')。fnSelectAll(true);
}
}
]
}
I have a datatables in which I can select multiple row onclick but how can I select all the row on a click of button and at the same time all rows are highlighted with selection (Can you please give example of selection for current page and all the pages). I have written a code to get multiple selected value.
Checkbox will also do but then how to get selected value.
Below is code for single and multiple selection.
var oTable = $("#example").dataTable();
$('#example tbody').on('click', 'tr', function() {
$(this).toggleClass('selected');
});
Code to get selected value on button submit.
var row = oTable.rows('.selected').data();
var jsonArr = "[";
if(row != null && row.length){
for (var i = 0; i < row.length; i++) {
var row1 = row[i]; // this will give me one row details
// row1[0] will give me column details
jsonArr = jsonArr + "{\"ID\":" + row1[0] + "},";
}
jsonArr = jsonArr + "]";
What will probably help you is TableTools extension. There is an example with select_all and select_none buttons, and those work for all pages.
One default limitation is that select_all will ignore current filtering, but that is easy to solve using the code below. Providing "true" argument to fnSelectAll enables the filter-aware selection.
tableTools: {
sRowSelect: 'multi',
aButtons: [
{
sExtends: 'select_all',
sButtonText: 'Select All',
fnClick: function (nButton, oConfig, oFlash) {
TableTools.fnGetInstance('example').fnSelectAll(true);
}
}
]
}
这篇关于选择Jquery Datatables中的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!