Exception error in postEdit event
Exception error in postEdit event

I use this event to reload the data from ajax after editing:
editor
.on( 'postCreate postRemove postEdit', function () {
// After create or edit, a number of other rows might have been effected -
// so we need to reload the table, keeping the paging in the current position
table.ajax.reload( null, false );
} )
The reload is needed as other records may change when I edit one of the columns. I see the following in the browser's console after inline editing. This error doesn't occur with form editing.
Uncaught TypeError: Cannot read property 'contents' of undefined
at Editor.inline (dataTables.editor.js:2994)
at dataTables.editor.js:2980
at dataTables.editor.js:5655
Its referring to this line in the Editor:
// Remove from DOM, keeping event handlers, and include text nodes in remove
var children = node.contents().detach();
Doesn't seem to cause any issues. I don't have the same problem with creating or removing rows. I tried adding the e, json, data
parameters to the function but still get the error. Commenting the ajax.reload
removes the error.
Let me know if I'm missing something.
Kevin
This question has an accepted answers - jump to answer
Answers
HI Kevin,
Try using
submitComplete
rather than thepost*
events.The problem there is that you will run into a timing error - Editor's own draw action isn't triggered until after the
post*
events (I'm close to considering that a bug actually, even although it was by design...) - so depending on the network latency, the draw might have happened by the time you get the ajax response, or it might not! Editor is then referencing DOM elements which no longer exist, hence the error.Hopefully just using that different event name should do it.
Regards,
Allan
Unfortunately I get the same error with
submitComplete
. Interestingly I'm not able to inline edit once I get the error where before there seemed to be no problems with functionality.I went back to using the
post*
events and added a 100ms delay usingsetTimeout
. This works with no errors. Thanks for the pointer about the potential race condition. Those are the most fun to find and fixKevin
Are you able to give me a link to a page showing the error? I can take a look and see if I can figure out what is going wrong.
Allan
Unfortunately its not easy to provide access. Not sure there is a way to recreate on your
live
site since Editor needs to update a table. If that is possible i can try that.If you have some ideas of what you want to look at I can try to capture them.
I'm ok with the setTimeout but if you think its an issue worth fixing for others I will do what I can. In my current environment MySql and all the JS and Python scripts are on the same box. I can probably lower the timeout but it seems ok.
Kevin
Sounds good - great to hear you have it working.
If you have the time, I think it would be interesting to know a little bit about the error. Could you tell me what version of Editor you are using and show me the full back trace from the error in the console? With that I'll have a think about what might cause the issue.
Thanks,
Allan
Is this the trace back info you want?
If you need more detail from it let me know how to get it. I'm using Chrome / Mac.
I'm using Editor 1.6.1.
Let me know other info you may want.
Kevin