.fnAddData removing columns classes
.fnAddData removing columns classes
stanmancan
Posts: 5Questions: 0Answers: 0
I'm trying to move rows between two tables. I'm using the following code below, but whenever the row gets added to the new table all of my 's are missing their custom classes. This is a problem as it effects the display and formatting of the data.
Any idea why the classes are being removed?
[code]
var table = $(this).closest("table");
var track = $(this).closest("tr");
var sourceTable = table.dataTable();
var completedTable = $("#tracks_outstanding").dataTable();
var row = track.get(0);
var addElement = sourceTable.fnGetData(row);
sourceTable.fnDeleteRow(sourceTable.fnGetPosition(row));
completedTable.fnAddData(addElement);
[/code]
This is the code of the row _before_ it's been moved:
[code]
18-OCT-13
[/code]
This is the markup _after_ it's been moved:
[code]
18-OCT-13
[/code]
Any idea why the classes are being removed?
[code]
var table = $(this).closest("table");
var track = $(this).closest("tr");
var sourceTable = table.dataTable();
var completedTable = $("#tracks_outstanding").dataTable();
var row = track.get(0);
var addElement = sourceTable.fnGetData(row);
sourceTable.fnDeleteRow(sourceTable.fnGetPosition(row));
completedTable.fnAddData(addElement);
[/code]
This is the code of the row _before_ it's been moved:
[code]
18-OCT-13
[/code]
This is the markup _after_ it's been moved:
[code]
18-OCT-13
[/code]
This discussion has been closed.
Replies
If you are feeling brave and want to give it a go, grab the latest dev code from: https://github.com/DataTables/DataTables/tree/1_10_wip/media/js and then use the new api:
[code]
var table = $('#myTable').DataTable();
table.row.add( copiedRow );
[/code]
where `copiedRow` is your TR element to copy into place. Note that capital `D` in the DataTable initialisation - that will give you the new API object.
I haven't tried this myself yet, so would be interested to know how you get on. It should work...
Allan
[code]
var destination = $("#tracks_outstanding").DataTable();
destination.row.add(td.closest("tr"));
[/code]
No errors, but the row certainly does not get added to the new table either.
Here is a running example where you can click on a row in each table to transfer it to the other:
http://live.datatables.net/exavar/edit
[code]
$(document).ready(function() {
var t1 = $('#t1').DataTable();
var t2 = $('#t2').DataTable();
$('#t1 tbody').on( 'click', 'tr', function () {
t1.row( this ).remove().draw();
t2.row.add( this ).draw();
} );
$('#t2 tbody').on( 'click', 'tr', function () {
t2.row( this ).remove().draw();
t1.row.add( this ).draw();
} );
} );
[/code]
And yes, DT 1.10 is backwards compatible (unless any private properties have been used, in which case it might break!). If you are using any of the extras, they might also need to be updated to their dev versions.
Allan