Add multiple rows from one data table to another using jQuery.
Add multiple rows from one data table to another using jQuery.
Satish_Lakhani
Posts: 4Questions: 1Answers: 0
Hey,
I'm having to separate data tables on a single page both having same json format with different data in it.
I want to add multiple selected rows from one data table to another.
How can i get this requirement..?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I'm having both the datatables server side &
fnAddData is not functioning in my case.
Kindly provide proper solution for this.
I also have a similar requirement .. were you able to solve yours ??
Below is a sample page that I build that simply adds and remove rows between two tables
$(document).ready(function() { var oTableSource = $('#source').DataTable(); var oTableDest = $('#destination').DataTable(); $('#source tbody').on( 'click', 'tr', function () { if ( $(this).hasClass('row_selected') ) { $(this).removeClass('row_selected'); } else { oTableSource.$('tr.row_selected').removeClass('row_selected'); $(this).addClass('row_selected'); } } ); $('#destination tbody').on( 'click', 'tr', function () { if ( $(this).hasClass('row_selected') ) { $(this).removeClass('row_selected'); } else { oTableDest.$('tr.selected').removeClass('row_selected'); $(this).addClass('row_selected'); } } ); $('#add').click( function() { oTableDest.row.add(oTableSource.row('.row_selected').data()).draw(); oTableSource.row('.row_selected').remove().draw( false ); } ); $('#remove').click( function() { oTableSource.row.add(oTableDest.row('.row_selected').data()).draw(); oTableDest.row('.row_selected').remove().draw( false ); } ); } );Let me know if this helps you too
<html>
<head>
</head>
<body>
Live example
</body>
</html>
Hi,
Thanks for your valuable response.
I'll try this.
But i've changed my mind to do this with some server side scripting using ajax call & redrawing the source table again after success of ajax call.
Thank You.
I have extended it a bit to get multiple selection and add / remove working below is the updated script :
$(document).ready(function() {