DataTables editor ajax, idSrc questions
DataTables editor ajax, idSrc questions
(I translate through Google translation and raise questions.)
I have two questions.
if SN is null, i want idSrc to be -1.
I tried, fields def : -1
But if IdSrc is null, the value was empty .
If /api/Member/Editor function return OK, always an ajax error.
state = "parsererror", errorCode = SyntaxError: Unexpected end of JSON input at parse (<anonymous>) at ajaxConvert (http://localhost:1885/Scripts/jquery-3.3.1.js:8788:44) at done (http://localhost:1885/Scripts/jquery-3.3.1.js:9256:28) at XMLHttpRequest.<anonymous> (http://localhost:1885/Scripts/jquery-3.3.1.js:9549:37)
Thanks for reading this article.
Below is my code.
.js code
$(document).ready(function () {
var editor = new $.fn.dataTable.Editor({
"ajax": {
"url": "/api/Member/Editor",
"type": "POST",
success: function () {
oTable = $('#demoGrid').DataTable();
oTable.draw();
},
error: function (response, state, errorCode) {
//error..
}
},
table: "#demoGrid",
idSrc: 'SN',
fields:
[
{
label: "SN",
name: "SN",
type: "hidden",
},
........
]
});
var table = $("#demoGrid").DataTable({
buttons: [
{ extend: "create", editor: editor,},
{ extend: "edit", editor: editor,},
//...
]
});
.cs code
[HttpPost]
public HttpResponseMessage Editor([FromBody]JObject request)
{
var action = request.GetValue("action").ToString();
//......
if(action == "create"){
//......
return Request.CreateResponse(HttpStatusCode.OK);
}
}
Replies
The id for a row cannot be null I'm afraid. If you want
null
to actually be -1, you'd need to modify your server-side code to make that mapping when the table is originally read.Allan