Add, Edit et Delete with datatabes 1.9.2
Add, Edit et Delete with datatabes 1.9.2
So, after to lose so many time to solve my bug, i decide to share all my work with anyone who want to work like me.
1) Add new row in existing tab: (after ajax request, put data in tab)
/* You need to include plugin .fnAddDataAndDisplay in http://www.datatables.net/plug-ins/api/fnAddDataAndDisplay.
copy Plug-in code and put it in your /js/file.js ans include it in your page like :
*/
<
script>
$.ajax({
type: 'POST',
url: '/to/my/ressource',
data:{'data1':data1,'data2':data2}, // all your request paraemter
timeout: 20000,
success: function(data) {
eval("var donnees = "+data+';');
row1=donnees.row1;
row2=donnees.row2;
row3=donnees.row3;
row4=donnees.row4;
// your can do here your control data or other thing
var table = $('#tabIn').dataTable(); // my tab exemple :
<
table id="tabIn" ......
table.fnAddDataAndDisplay( [row1,row2 ,row3,row4] );
},
error: function(request) {
// alert_message("Erreur de transmission de données"); your own alert if ajax error
}
});
</script>
2) Edit existing row
//after ajax like the first parapgraph
row1=donnees.row1; row2=donnees.row2; row3=donnees.row3; row4=donnees.row4; table = $('#tabIn').dataTable(); row = $("#"+idindex+'row').parent().parent()[0]; // you have to find method to repair all row with id, for me // i do : /*3) to deleted
//after ajax
row = $("#"+idindex+'row').parent().parent()[0]; table = $('#tabIn').dataTable(); table.fnDeleteRow( nRow, null, true );HOPE CAN HELP SOMEONE TO DO NOT LOSE TIME LIKE ME!