Jquery 数据表在单击按钮时获取行数据
Jquery Datatables get row data on button click
我想在单击按钮时获取特定行列数据。这是我的代码
var oTable = $('#grid').dataTable({
"scrollCollapse": true,
"paging": false,
'aaData': dtData,
'bPaginate': false,
'bInfo': false,
"ordering": false,
"bProcessing": true,
'bFilter': true,
destroy: true,
"aoColumns": [null,null,null,null,
{
"mData": null,
"bSortable": false,
"mRender": function (o) { return '<a href="">'+"<img src='images/gridchart.png'></img>" +'</a>'; }
},
{
"targets": [5],
"visible": false,
"searchable": false
},
{
"targets": [6],
"visible": false,
"searchable": false
}
]
}).rowGrouping();
问题是最后两列根本没有添加到 dom,所以我无法检索它们各自的值
欢迎任何帮助
您可以将最后 2 行值添加为 link 的数据属性,如下所示:
'mRender': function (data, type, full) {
return '<a data-col4=\'' + full[4] + '\' data-col5=\'' + full[5] + '\' href="">'+"<img src='images/gridchart.png'></img>" +'</a>';
}
full
参数是数据表行的数据源,因此即使没有显示值,它们仍然可用。
您必须使用 jQuery 来检索这样的值:
$('#grid tbody').on('click', 'a', function (e) {
e.preventDefault();
var col4Val = $(this).data('col4');
var col5Val = $(this).data('col5');
// you would then redirect to the link using window.location.href, adding the col4 & col5 values as querystring parameters
}
或者,您可以在渲染 link 时将参数添加到 url - href
中没有任何内容,所以我假设您是使用 jQuery 单击事件处理此问题。
我想在单击按钮时获取特定行列数据。这是我的代码
var oTable = $('#grid').dataTable({
"scrollCollapse": true,
"paging": false,
'aaData': dtData,
'bPaginate': false,
'bInfo': false,
"ordering": false,
"bProcessing": true,
'bFilter': true,
destroy: true,
"aoColumns": [null,null,null,null,
{
"mData": null,
"bSortable": false,
"mRender": function (o) { return '<a href="">'+"<img src='images/gridchart.png'></img>" +'</a>'; }
},
{
"targets": [5],
"visible": false,
"searchable": false
},
{
"targets": [6],
"visible": false,
"searchable": false
}
]
}).rowGrouping();
问题是最后两列根本没有添加到 dom,所以我无法检索它们各自的值
欢迎任何帮助
您可以将最后 2 行值添加为 link 的数据属性,如下所示:
'mRender': function (data, type, full) {
return '<a data-col4=\'' + full[4] + '\' data-col5=\'' + full[5] + '\' href="">'+"<img src='images/gridchart.png'></img>" +'</a>';
}
full
参数是数据表行的数据源,因此即使没有显示值,它们仍然可用。
您必须使用 jQuery 来检索这样的值:
$('#grid tbody').on('click', 'a', function (e) {
e.preventDefault();
var col4Val = $(this).data('col4');
var col5Val = $(this).data('col5');
// you would then redirect to the link using window.location.href, adding the col4 & col5 values as querystring parameters
}
或者,您可以在渲染 link 时将参数添加到 url - href
中没有任何内容,所以我假设您是使用 jQuery 单击事件处理此问题。