第一次在这里发帖,但我真的需要帮助。在这个小项目上工作了一段时间,我发现 Datatables 几乎没用,但我被告知我必须使用它......无论如何,我已经得到它显示我们从 ajax 调用到我们的 SQL 服务器的表。它需要让用户选择几行并单击删除按钮。然后它应该从每个选定的行中获取 ID 并通过 ajax 调用将其传递回我们的服务器,然后服务器将删除该值。
我尝试了大约 5 种差异行选择方法,更多的删除尝试然后我可以数数,但没有任何工作。在过去的几周里,我多次在他们的支持网站上寻求帮助,但没有得到一个答复,所以希望这里的人们能够提供更多帮助:)
无论如何继承我的代码:JSFIDDLE UPDATED TO CURRENT
$(document).ready(function(){
var oTable = $('#dataTable').dataTable({
//"bServerSide": true,
"bProcessing": true,
"bJQueryUI": true,
"bPaginate": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 10,
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"sDom": 'pT<><f>rt<il>',
"sAjaxSource": 'dataTable/getCmsGroupData',
"aoColumns": [
{ "mData": "id", "sTitle": "ID",
"fnRender": function (oObj) {
return '<a href="cmsgroup_update?id='+ oObj.aData["id"] + '">' + oObj.aData["id"] + '</a>';
}},
{ "mData": "version", "sTitle":"Version" },
{ "mData": "name", "sTitle": "Name" },
{ "mData": "description", "sTitle": "Description"},
{ "mData": "notes", "sTitle": "Notes"},
],
"oTableTools": {
"aButtons": [
"select_all",
"select_none",
{
"sExtends": "text",
"sButtonText": "Create New Entry",
"fnClick": function ( nButton, oConfig, oFlash ) {
window.location = "cmsgroup_add";
}
}]
}
});
$("#dataTable tbody").click(function(event) {
$(oTable.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i<aTrs.length ; i++ )
{
if ( $(aTrs[i]).hasClass('row_selected') )
{
aReturn.push( aTrs[i] );
}
}
return aReturn;
}
$("#delete").click(function(){
selected = fnGetSelected(oTable);
oTable.fnDeleteRow( selected[0]);
$.ajax({
type: "POST",
url: "dataTable/delete/cmsGroup",
data: 'tableData='+ $(selected).text(),
success: function(result) {
alert("worked!");
}
});
});
} );
任何帮助都会很棒!!!