Inline edit : Uncaught TypeError: Cannot read property 'contents' of undefined
Inline edit : Uncaught TypeError: Cannot read property 'contents' of undefined
Hello,
I have the following problem:
When I update the row, the row disappears and in the console I get this warning:
Uncaught TypeError: Cannot read property 'contents' of undefined
I use DataTables 1.10.10 and Editor 1.5.3.
I pull and update the data with REST-API and AJAX.
Column definition
Object {data: "emp_id", class: "cell_right_aligned readonly", width: "10%", editField: "emp_id", title: "Pers.Nr."}
Object {data: "emp_name", class: "readonly", width: "30%", editField: "emp_name", title: "Name"}
Object {title: "Steuerung ganze KW", data: "(null)", width: "20%", className: "center", defaultContent: "<a href="" class="editor_set_present">A</a><a href…p">D</a><a href="" class="editor_set_other">S</a>"}
Object {data: "func_day1", editField: "func_day1", title: "Mo", width: "5%", class: "sd_function"…}
Object {data: "func_day2", editField: "func_day2", title: "Di", width: "5%", class: "sd_function"…}
Object {data: "func_day3", editField: "func_day3", title: "Mi", width: "5%", class: "sd_function"…}
Object {data: "func_day4", editField: "func_day4", title: "Do", width: "5%", class: "sd_function"…}
Object {data: "func_day5", editField: "func_day5", title: "Fr", width: "5%", class: "sd_function"…}
Object {data: "sd_sickreason_name", class: "sickreason", width: "30%", visible: false, name: "sd_sickreason_name"…}
bVisible: true
class: "sickreason"
data: "sd_sickreason_name"
editField: "sd_sickreason"
mData: "sd_sickreason_name"
name: "sd_sickreason_name"
sClass: "sickreason"
sName: "sd_sickreason_name"
sTitle: "Krankheitsgrund"
sWidth: "30%"
title: "Krankheitsgrund"
visible: true
width: "30%",
}
Object {data: "sd_tripreason", class: "tripreason", width: "30%", visible: true, name: "sd_tripreason"…}
Editor field definition
Object {name: "emp_id", label: "Pers.Nr."}
Object {name: "emp_name", label: "Name"}
Object {name: "func_day1", label: "Mo", def: "-"}
Object {name: "func_day2", label: "Di", def: "-"}
Object {name: "func_day3", label: "Mi", def: "-"}
Object {name: "func_day4", label: "Do", def: "-"}
Object {name: "func_day5", label: "Fr", def: "-"}
Object {type: "select", label: "Krankheitsgründe:", name: "sd_sickreason", options: Array[3]}
Object {name: "sd_tripreason", label: "Reiseziel/grund", default: ""}
JSON-Response from Datatables
data: [{
0: {emp_id: 687, emp_name: "XXXX, Andreas ", sd_sickreason: "2",…}
DT_RowId: "row687"
emp_id: 687
emp_name: "XXXX, Andreas "
func_day1: "D"
func_day2: "D"
func_day3: "A"
func_day4: "D"
func_day5: "D"
sd_sickreason: "2"
sd_sickreason_name: "OP"
sd_tripreason: ""
1: {emp_id: 966, emp_name: "XXXX, Enrico ", sd_sickreason: "1",…}
DT_RowId: "row966"
emp_id: 966
emp_name: "XXXX, Enrico "
func_day1: "K"
func_day2: "K"
func_day3: "K"
func_day4: "K"
func_day5: "K"
sd_sickreason: "1"
sd_sickreason_name: "Erkältung"
sd_tripreason: "g"
2: {emp_id: 1110, emp_name: "XXXX, Kadir ", sd_sickreason: "1",…}
DT_RowId: "row1110"
emp_id: 1110
emp_name: "XXXXX, Kadir "
func_day1: "K"
func_day2: "K"
func_day3: "A"
func_day4: "s"
func_day5: "K"
sd_sickreason: "1"
sd_sickreason_name: "Erkältung"
sd_tripreason: ""
draw: 1
recordsFiltered: 3
recordsTotal: 3}]
JSON-Response after submit
data: [,…]
0: {
DT_RowId: "row966"
emp_id: "966"
emp_name: "XXXX, Enrico "
func_day1: "K"
func_day2: "K"
func_day3: "K"
func_day4: "K"
func_day5: "K"
sd_sickreason: "2"
sd_tripreason: "g"
}
Click event for inline edit
// Inline editing on click
$(tablename).on( 'click', 'tbody td:not(:nth-child(3))', function (e) {
// console.log('inline');
editor.inline( this, {submit:'allIfChanged' , submitOnBlur: true} );
} );
I have tried a lot of things, but nothing solved this problem.
Has somebody a suggestion how to get rid of this exception?
Thank you very much in advance.
Best regards,
Sascha
This question has an accepted answers - jump to answer
Answers
This suggests that the server is not responding with the JSON data that Editor requires. The information you provide above would appear to suggest otherwise though.
Could you link to the page so I can debug it directly please.
Allan
Check out my fiddle that uses this binding for knockout --> pretty slick for editable datatables!
https://www.datatables.net/forums/discussion/31797/knockout-js-3-4-custom-binding-for-jquery-datatables-net#latest
Link to example fiddle in discussion.
Dear Allan,
unfortunately this project only exists on dev system which is not available to public.
I can provide you the php script which is responsible for updating the row(s)
function init_Editor(fields)
{
}
```
as such as the initialisation of data tables:
Here is additionally the detailed output from console:
error was thrown at
var children = node.contents().detach()
Can I provide you something else?
Looking at the JSON response again, it looks like it might be a little wrong although its hard to tell with that formatting. Can you post the raw JSON that is returned from the server, not the code that is formatted by the browser?
Thanks,
Allan
Hello Allan,
yes of course:
I think it belongs on the editor field with type 'select'.
If i replace this field with a simple input field the error does not appear.
Thanks for the details!
Interestingly someone else just posted almost exactly the same issue - I've written up a detailed reply with how to fix it. Exactly the same fix will apply here - you need to pass the index into
inline()
rather than the node (this
).Regards,
Allan
Hello Allan,
no problem.
Thank you for helping me.
Best regards,
Sascha