Delete option for rows, possibility to 'drop' columns from live view

Delete option for rows, possibility to 'drop' columns from live view

Thenorman138Thenorman138 Posts: 2Questions: 2Answers: 0
edited May 2017 in Free community support

This is my current script for my 2 datatables:

<script type="text/javascript"   src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
(function($) {
$(document).ready(function() {
$('#mytable').DataTable();
$('#mytableSurvey').DataTable();
$('.dataTable').wrap('<div class="dataTables_scroll" />');


 $(document).on('change' , '#select-tables', function(){
 var table = $(this).val();
 $('#' + table +'_wrapper').show();
 $('[id$="_wrapper"]').not('#' + table +'_wrapper').hide();
 });
 $("#select-tables").trigger("change");

 });
}(jQuery));
</script>

The tables work perfectly, and I have them attached to a select box to show one and hide the other, depending on the selection.

However, I now have 2 tasks I'm trying to achieve:

The first, which I've not seen much, is the ability to 'drop' or remove an entire column from the live view of the table, but this wouldn't remove or modify in the database, simply the view. So, if the page is refreshed, the table goes back to normal with dropped columns added back on. I have no ideas here.

My second task, which I've seen implemented in many ways, is to add a delete/remove button to each row that WOULD remove from the database as well. I'm running this on a wordpress site, so I'd like to keep the code inline if possible. I know this can be done with the Editor plugin, and that may be the best, but I'm looking for the best way to implement the delete button into my current table code. A checkbox option would work as well, as long as I have the ability to remove any row.

Any help here is greatly appreciated.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Answer ✓

    The first, which I've not seen much, is the ability to 'drop' or remove an entire column from the live view of the table, but this wouldn't remove or modify in the database, simply the view.

    row().remove() would do it. That is a client-side only method so it won't effect the database. Normally this question gets asked the other way around - "when I call row().remove() the row isn't removed from my database"!

    My second task, which I've seen implemented in many ways, is to add a delete/remove button to each row that WOULD remove from the database as well

    This is how it can be done with Editor.

    If you don't want to use Editor, you would need to make an Ajax call to the server to tell it to delete the row.

    Allan

This discussion has been closed.