Leo*_*han 6 javascript jquery datatables
我正在使用jquery插件Datatables来操纵我的行实际上它有一个tabletools插件,允许checkall功能,但是,我可以检查所有项目/检查多个,但是如何添加删除按钮 并返回选中的行?
我已经有删除sql查询和删除警告弹出框的功能.
谢谢
$(document).ready( function () {
$('#viewSub').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "../plugin/DataTables-1.9.0/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf",
"sRowSelect": "multi",
"aButtons": [
"select_all",
"select_none",
"copy",
"print",
"delete", <===********can not add here, seems only allow pre-defined button.
{
"sExtends": "collection",
"sButtonText": "Save",
"aButtons": [ "csv", "xls", "pdf" ]
}
]
}
} );
} );
Run Code Online (Sandbox Code Playgroud)
您可以添加一个函数来捕获选定的行:
$(document).ready( function () {
$('#example').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"fnRowSelected": function ( node ) {
alert( 'The row with ID '+node.id'+ was selected' );
}
}
} );
} );
Run Code Online (Sandbox Code Playgroud)
例如,在此函数中,您可以将隐藏字段的设置值添加到此按钮node.id,将其添加到简单的<button>Delete</button>处理onClick程序中,以删除具有选定 id 的行。
检查也回答了这个问题。