I’ve add DataTables Editable to my table to able to add and delete some rows.
The add part works great, but I’m having some problem with the delete part, because I can’t select the rows.
By what I’ve seen in the example all I’ve to do is to add the delete URL, something like this:
.makeEditable({sDeleteURL: “/DeleteURL”});
But that dosent make my rows selectable so I can delete anthing.
My full code is:
$(function () {
var oTable = $('.table-@Model.Numero').dataTable(
{
"oLanguage": { "sUrl": "/LanguageURL" },
"bProcessing": true,
"bFilter": false,
"sPaginationType": "full_numbers",
"iDisplayLength": 10,
"bLengthChange": false,
"aoColumnDefs": [{ "sClass": "center-col", "aTargets": ['align-center-col'] },
{ "sClass": "read_only", "aTargets": ['read-only-col'] },
{ "sClass": "small-width-col", "aTargets": ['small-col'] }],
"aaSorting": [[0, "desc"]],
"bScrollCollapse": true,
"bServerSide": true,
"sAjaxSource": '/DataURL',
"fnServerData": function (sSource, aoData, fnCallback) {
aoData.push({ "name": "Numero", "value": $(this).find("#Numero").val() });
$.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
});
}
}).makeEditable({
sAddNewRowFormId: 'form-@Model.Numero',
sAddNewRowButtonId: 'btn-@Model.Numero',
btnDeleteRow: 'btn-del-@Model.Numero',
sAddURL: "/AddURL",
sDeleteURL: "/DeleteURL"
});
});
I’ve personally been playing around with getting the datatables delete function to work for one of my projects.
What I’ve found is I needed to include the
jquery-ui.jsscript in the head of the document.I also discovered that you need to format your table rows like this.
<tr id="1">so that datatables can automatically grab the correct id # from the selected row and pass it on to your php page for further processing.Datatables can automatically add an id to each table row through the use of
DT_RowIdspecial property.If you have set up datatables to use server side implementation, then you can include
DT_RowIdin the JSON data returned from the server in response to the ajax request .For example JSON format:
Here is my example mockup code. Server side implementation isn’t included with this example I’m just using the example source objects.txt that came with datatables for an example.
NOTE You may have to change the script and Style URL paths to where yours are located in order to see a working example.
Update: You also need to manually include this anywhere in your HTML source.