Inline Editing with asp.net webservices.
Inline Editing with asp.net webservices.
rimshot609
Posts: 9Questions: 6Answers: 0
I'm trying to edit a jQuery DataTable using web-services in .Net. I'm able to load the data into the table okay and have the edit/delete/new buttons showing but can't seem to figure out how to Edit the table by passing the parameters to the UpdateTable WebMethod. I've seen others post here trying to do something similar but no clear answers. Most of what I find is using PHP or MVC. I think I'm getting close but stuck here:
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function () {
editor = new $.fn.dataTable.Editor({
ajax: "../WebService1.asmx/UpdateTable",
table: "#example",
fields: [{
label: "First name:",
name: "FirstName"
}, {
label: "Last name:",
name: "LastName"
}
]
});
});
// Activate an inline edit on click of a table cell
$('#example').on('click', 'tbody td:not(:first-child)', function (e) {
editor.inline(this);
});
$.ajax({
url: '../WebService1.asmx/GetTable',
method: 'post',
dataType: 'json',
success: function (data) {
$('#example').dataTable({
dom: "Bfrtip",
paging: true,
sort: true,
searching: true,
scrollY: 200,
data: data,
columns: [
{
defaultContent: '',
className: 'select-checkbox',
orderable: false
},
{ data: "FirstName" },
{ data: "LastName" }
]
,
select: {
style: 'os',
selector: 'td:first-child'
},
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]
});
}
});
This discussion has been closed.
Answers
Hi,
Can you show me the JSON data that is being returned by your web method for the update submit? It needs to conform with the JSON Editor expects (or use
postSubmit
to transform whatever is returned into what Editor expects).Allan
Allan,
These are the only two rows being returned. Is this what you're needing to see?
Yes thank you - and that indeed doesn't conform with what Editor is expecting. It need a JSON object with the information about the edited row(s) in a
data
property.Allan
Allan, is purchasing a license required in order for the datatables editing feature to work? Thanks.
Hi @rimshot609 ,
Yep, Editor is the only licensed component of DataTables.
Cheers,
Colin