Add /Remove data between two datatables
Add /Remove data between two datatables
Hi,
I am trying to Add/ Remove data between two datatables, but i am getting an error.
Please find the code snippet in below:
I am getting following below error, when i try to add data from one datatable to another datatable.
" Datatables warning (table id='destination'): Requested unknown parameter '0' from the data source for row 0".
Please help me out.
Thanks,
Vishal
This discussion has been closed.
Replies
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
DataTables example
@import "../../media/css/demo_page.css";
@import "../../media/css/demo_table.css";
var oTable;
var giRedraw = false;
$(document).ready(function() {
/* Add a click handler to the rows - this could be used as a callback */
$("#source tbody").click(function(event) {
$(oTableSource.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
/* Add a click handler for the delete row */
$('#add').click( function() {
var anSelected = fnGetSelected(oTableSource);
oTableDest.fnAddData(anSelected[0]);
} );
/* Init the table */
oTableSource = $('#source').dataTable({"aoColumns": [{ "sTitle": "Rendering engine" }]});
oTableDest = $('#destination').dataTable({"aoColumns": [{ "sTitle": "Rendering engine" }]});
} );
/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i>
Removed>>
Rendering engine
[/code]
Looks like the forum totally butchered your post... I've just made some changes and reposted your code to get the correct formatting.
I suspect that this is bit that is causing a problem:
[code]
var anSelected = fnGetSelected(oTableSource);
oTableDest.fnAddData(anSelected[0]);
[/code]
It looks to me that you are trying to add a node to the new table by using fnAddData. However as the documentation for fnAddData notes, it expects an array (or object) of data - not a node. If you want to use a node then you can use this plug-in: http://datatables.net/plug-ins/api#fnAddTr .
Allan
I modified the code, but now it is giving me following error:
"Object does support this property or method".
[code]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">;
DataTables example
@import "../../media/css/demo_page.css";
@import "../../media/css/demo_table.css";
var oTable;
var giRedraw = false;
$(document).ready(function() {
/* Add a click handler to the rows - this could be used as a callback */
$("#source tbody").click(function(event) {
$(oTableSource.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
/* Add a click handler for the delete row */
$('#add').click( function() {
var row = fnGetSelected(oTableSource);
oTableDest.fnAddTr(row);
} );
/* Init the table */
oTableSource = $('#source').dataTable({"aoColumns": [{ "sTitle": "Rendering engine" }]});
oTableDest = $('#destination').dataTable({"aoColumns": [{ "sTitle": "Rendering engine" }]});
} );
/* Get the rows which are currently selected */
function fnGetSelected( oTableLocal )
{
var row;
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i>
Removed>>
Rendering engine
[/code]
Please help in this regards.
Regards,
Vishal
[/code]
Allan