Server Side Row Deletion
Server Side Row Deletion
Hi again everyone. I have another question, and again I apologize if it is very basic and an easy solution. I have a table that is server-side JSON with a column at the end labeled "Actions". For each row, there is a three options available: Manage, Defer, and Hide. All three actions have the result of deleting the row, as the table lists items that need attention, and taking an action on an item removes it from that list, regardless of what the action itself is.
This is the relevant PHP:
[code]
$sOutput .= '"' . "Manage | Hide | Defer" . '",';
[/code]
This results in output of:
[code]
Manage | Hide | Defer
[/code]
What I would like to do is remove that row from the list, and then write a message above the table to the effect of "You have successfully [action]ed this item." However, the quick and dirty jQuery I wrote is not working:
[code]
$('a.hide').click(function() { // and a.manage, etc.
oTable.fnDeleteRow(this.parent.parent());
});
[/code]
Anyone have some advice?
This is the relevant PHP:
[code]
$sOutput .= '"' . "Manage | Hide | Defer" . '",';
[/code]
This results in output of:
[code]
Manage | Hide | Defer
[/code]
What I would like to do is remove that row from the list, and then write a message above the table to the effect of "You have successfully [action]ed this item." However, the quick and dirty jQuery I wrote is not working:
[code]
$('a.hide').click(function() { // and a.manage, etc.
oTable.fnDeleteRow(this.parent.parent());
});
[/code]
Anyone have some advice?
This discussion has been closed.
Replies
Unfortunately fnDeleteRow doesn't really cut it for use with server-side processing, as it doesn't tell the server about the row being deleted (therefore, when you next request a table redraw, it will in fact show up again). So what needs to happen, is an Ajax request is sent to the server telling it to delete the row - then simply call 'fnDraw' on the table to redraw with the updated information in the database.
So an Ajax query to the server ( http://api.jquery.com/jQuery.ajax/ ) is the place to start. The reason this isn't built into DataTables, is that it doesn't have any information about which row you want deleted in the database, assuming you are even using a database, or what engine it has!
Regards,
Allan
Thank you for the quick reply. I realized after you replied that I did a poor job of phrasing my question. I do not want to delete the row from my database, but I would like to delete it from the data table. Think of the data table as a list of unread mail; once a row is "read", it doesn't necessarily need to be deleted from the database, but it doesn't need to show up in the data table, either. I suppose one solution would be to have an field in my database of whether or not a row has been read or not, and simply update it via AJAX and then redraw the table.
Another problem I am running into is within the jQuery code I posted. I have a listener created for $('a.hide') but even when I click on the link with the hide class, that block is never reached for whatever reason. Is that because of the server-side table?
Okay got it now. I guess you must have some logic somewhere already to say if something should be included in the table or not at the first draw (i.e. it's been read or not). Is this a database field which says the date/time of reading perhaps? The same basic principle still applies - you'll need to update the database such that the row is in the 'read' state, and then redraw the table to get the new information from the server.
Regarding the jQuery event - see the question entitled "My events aren't being applied" in the server-side processing section of the FAQs ( http://datatables.net/faqs ) - it's right at the bottom of the page.
Regards,
Allan