如何从数据表中获取复选框的值?
问题描述:
我想从数据表中获取选定的复选框值,在我的表中,我有两列,第一列用于复选框,第二列用于显示值。
I want to get the selected checkbox value from the data table, in my table, I have two columns and the first one is for checkbox and the second one is for display values.
这里只是返回一个复选框。我们怎么知道有点击发生?
帮帮我。
Here is just returning a checkbox. How can we know that there is click happens? Help me.
这是代码
function BindColumSelectTable(DataExchangeList) {
debugger
$('#columnSelectTable').DataTable({
"data": DataExchangeList,
"destroy": true,
"columns": [
{
data: 'check', render: function (data, type, row) {
debugger;
return '<input type="checkbox"/>'
}
},
{ data:"FieldCaption" },
],
"columnDefs": [
{
orderable: false,
className: "select-checkbox",
targets:0
},
{ className:"tabletdAdjust","targets":[1]}
],
});}
我正在使用jquery数据表
I'm using jquery data table
答
这是我为每次点击使用 onclick
函数的答案将触发功能n
Here is the answer I use onclick
function for each click it will trigger the function
function BindColumSelectTable(DataExchangeList) {
debugger
$('#columnSelectTable').DataTable({
"data": DataExchangeList,
"destroy": true,
"columns": [
{
data: 'ColumnCheck', render: function (data, type, row) {
debugger;
return '<input type="checkbox" onclick="ColumnCheck(this)"/>'
}
},
{ data:"FieldCaption" },
],
"columnDefs": [
{
orderable: false,
className: "select-checkbox",
targets:0
},
{ className:"tabletdAdjust","targets":[1]}
],
});
}
the above code is the same i used in the question only one thing i added is an onclick function
and the onclick function is
function ColumnCheck(thisObj) {
debugger;
var dataExchangeCheckColumnVM = $('#columnSelectTable').DataTable().row($(thisObj).parents('tr')).data();
var dataExchangeCheckColumnList = $('#columnSelectTable').DataTable().rows().data();
for (var i = 0; i < dataExchangeCheckColumnList.length; i++) {
if (dataExchangeCheckColumnList[i].FieldCaption !== null) {
if (dataExchangeCheckColumnList[i].FieldCaption === dataExchangeCheckColumnVM.FieldCaption) {
dataExchangeCheckColumnList[i].ColumnCheck = thisObj.checked;
}
}
}
_dataExchangeColumnList = dataExchangeCheckColumnList;
}
所以我使用了** ColumnCheck **属性,它是布尔变量。在每次迭代中,如果选中复选框,它将添加一个真值
so i used an property **ColumnCheck ** it is boolean variable. on each iteration it will added a true value if check box is checked