first time posting here but i really need help. Been working on this little project for a while and am finding Datatables to be next to useless but im being told i must use it....anyway Ive got it displaying our table from an ajax call to our SQL server. It needs to let the user select a few rows and click a delete button. It then SHOULD get the ID from each selected row and pass it back via an ajax call to our server which will then delete the value.
Ive tried about 5 diff row select methods, more delete attempts then i can count, and NOTHING is working. Ive asked for help on their support site several times over the past couple weeks and havent gotten a single reply so hoping the people here may be able to help more :)
Anyway heres my code: 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!");
}
});
});
} );
Any help would be great!!!