Impossible to reload my dataTable following a delete row
Impossible to reload my dataTable following a delete row
beegeezzz
Posts: 12Questions: 3Answers: 0
Hello,
I try for several hours to reload my dataTable, no success until now...
This is my json object received from the server to js
{"0":{"id":"123","nom":"G\u00e9om\u00e8tre","prenom":"Barack","adresse":null,"numero":null,"boite":null
,"cp":null,"ville":null,"mail":null,"telephone":null,"inami":null,"tva":null,"disponibilite":null,"commentaire"
:null},"1":{"id":"128","nom":"G\u00e9om\u00e8tre-expert","prenom":"Barack","adresse":null,"numero":"6"
,"boite":"3","cp":"1300","ville":"Bruxelles","mail":"contact@dubinfo.be","telephone":"0471301253","inami"
:"5533434343","tva":"BE 0832.581.586","disponibilite":null,"commentaire":null}}
This is my code in js
$.ajax
(
{
method : 'POST',
//la route (controleur) et le paramètre (id à supprimer)
url: url + "/professionnels/deleteProfessionnels/"+id_to_delete,
dataType: 'json',
success:function(retour)
{
$('#example').dataTable().ajax.reload();
Errors
TypeError: $(...).dataTable(...).ajax is undefined
I tried a lot of possibilities, no success.
Thank you in advance for your help.
This discussion has been closed.
Answers
Please don't post duplicate questions. Please look at the response in your other thread:
https://datatables.net/forums/discussion/44367/datatable-does-not-work-with-genereted-html#latest
And take a look at the first FAQ here regarding this
TypeError: $(...).dataTable(...).ajax is undefined
:https://datatables.net/faqs/index#Most-common-FAQs
Kevin
Thank you Kevin and sorry for the duplicate post.
By the way, I tried the clear method, no success
TypeError: $(...).dataTable(...).clear is not a function
Thanks again for all
Did you read the FAQ I mentioned?
You need to change from
$('#example').dataTable().clear();
to$('#example').DataTable().clear();
. Notice DataTable has a capital D.Kevin
Thank you for your reply.
I don't have any error, but the table stills present, the clear function makes nothing.
But, I'm using clear in an ajax function, not in the ajax dataTable, is it ok ?
This is my dataTable code
This is my code
Thanks for your help
According to the
clear()
docs you need to redraw the table:Try:
$('#example').DataTable().clear().draw();
Kevin
Thank you, the table is clear, but no redraw...
Have I to give a json object ?
You can see the video here : dubinfo.be/kevin.mov
Hope I will be able to build the table, it will be great...
Thanks again
The table is redrawn. Its redrawn with no data from the clear command. Now you will use
rows.add()
to add your data.After seeing the video a better option may be to remove the row from the table using
row().remove()
. This way you won't need to reload the table each time someone deletes a row.Kevin
Hi Kevin,
I'm so happy, it's working....
Thank you so much for your precious help and mainly for your patience...
This is the code I used, I am able to remove row from the dataTable (if confirm) and then remove the row from the database with AJAX.
Again, thank you for all and have a great day.
David