Matching DataTable/Mysql-Table indexes for a proper delete.
Matching DataTable/Mysql-Table indexes for a proper delete.
Hi, i'm using the DT nice stuff to display the content of a MySql table (localhost DB).
Now, i want to delete the selected raw(s) on dataTable, but here is my problem:
1- i use the 'fnGetSelected' DT-Tools extension to get all selected rows (i absolutely need to get an array with indexes as i use the Eloquent ORM, so can't use the ajax implemented server-side...)
2- i then use the $.post trick to "submit" the indexes to my php server page 'suppress_id.php'...
code below:
"fnClick": function(){
var tt = TableTools.fnGetInstance( 'dt_contacts' );
var indexes = tt.fnGetSelectedIndexes();
if(indexes.length>0)
$.post(window.location.href='suppress_id', indexes);
}
==> Results:
:) -> routing (redirect to php page) for submit works.
:( -> i have problem with indexes value: always '1' (even selecting different rows and having tested it with alert() before submit..)
:( -> i have problem of matching indexes value order from DT with the mysql table after multiple deletings of rows (because index values are no more in order: 1/6/7/9/..).
So thanks for helping me solving those 2 bad points.
Replies
Well found so far, here my solution:
on JS side:
On server side:
This worked for me to delete correct Matching selected rows with DB-Table lines :)
PS: Just a thing, why can't we directly convert at "DT-Application" structure to an Array with toArray() ?