update cell on ajax success
update cell on ajax success
crush123
Posts: 417Questions: 126Answers: 18
Further to my original question on this thread http://datatables.net/forums/discussion/32872/
i am having problems with updating a cell in my table, which should be done only on ajax success.
What I want to do is simply set the cell value to a string value
table.cell( $(this).closest('tr'), 5 ).data( 'Re-subscribed Successfully' )
which works, but not on success
success: function(data) {
console.log('Success!', data);
var table = $('#example').DataTable();
//table.cell( $(this).closest('tr'), 5 ).data( 'Re-subscribed Successfully' )
setTimeout( function () {
table.draw();
}, 1500 );
},
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Is that your exact code above? If so, your problem is with the edited out code:
i edited out the line as it is this which causes the error within the ajax success function, but works perfectly outside of it
Have you tried it without the setTimeout function at the end?
You can call a redraw via the console to see if it fires then.
Yes, I think it's the way datatables handles ajax success
I've not had any trouble calling functions in a success return and there's nothing particularly complex about the function you're attempting to call.
One last thing from me.. there is a semi colon missing:
Should be
thanks for that spot, and for all of your input.
unfortunately the problem persists, i still get the error
interestingly, if i dont try to update the table cell, and instead just write to the dom it works ok
Thank you for posting the error.
What is
this
in your Ajaxsuccess
function? it isn't likely to be thetd
cell - I think jQuery executes that Ajax success in awindow
context (although I might be wrong). Have you checked to see whatthis
is? I'd suggest you get the row node before you make the Ajax call so you can keep the scope of execution.Could you possibly post continuation questions in the same thread in future, it just makes it a little easier to track the issue.
Thanks,
Allan
sorry, working at the limits of my knowledge here.
I cant work out how to get the row node. I tried the API reference but no joy
The row data is table.row($(this).closest('tr')).data(); but thats as close as i can get
You need to get it before you execute the Ajax request - when
this
is still the node.If you are still having problems with that please post the full chunk of code for the event handler.
Allan
thanks allan
here is my code snippet...
The most minimal change would be:
Obviously it could be tidied up more so
row
is used to getmyclass
andemail
.Allan
perfect, thanks (yet again) for your great support