first post but i really need help. For a while I was working on this small project and found that Datatables would be next to useless, but they were told that I should use it ... In any case, Ive got it by mapping our table from an ajax call to our SQL server. It should allow the user to select multiple lines and click the "Delete" button. Then it MUST retrieve the identifier from each selected row and pass it back through an ajax call to our server, which will then remove the value.
Ive tried about 5 row selection methods, more deletion attempts, I can count, and NOTHING works. Ive asked for help on their support site several times over the last couple of weeks, and havent received one answer, so hope that people here can help more :)
Anyway heres my code: JSFIDDLE UPDATED 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 !!!