fnAddData not working with object
fnAddData not working with object
Eph
Posts: 3Questions: 0Answers: 0
If I try to add some data to my DataTable by using an object, I get an error.
I've got it narrowed down to this code in the function '_fnAddData':
[code]
var aDataIn = ($.isArray(aDataSupplied)) ?
aDataSupplied.slice() :
$.extend( true, {}, aDataSupplied );
[/code]
This piece of code returns an empty object, but I don't really get what you are trying to do here.
By the way as stated in the documentation 'fnAddData', should be able to handle an object.
But the first line in that method is this:
[code]if ( mData.length === 0 )
{
return [];
} [/code]
Thus you have to wrap the object in an array instead of just passing the object.
EDIT:
Event when I convert the object to an array, I still get the same error. So I'm guessing 'fnAddData' is conflicting with the use of aoColumns, could that be right? The error I get is this one: [quote]DataTables warning (table id = 'assignedUserGroupsTable'): Requested unknown parameter 'id' from the data source for row 1[/quote] in this method '_fnGetCellData'.
I've got it narrowed down to this code in the function '_fnAddData':
[code]
var aDataIn = ($.isArray(aDataSupplied)) ?
aDataSupplied.slice() :
$.extend( true, {}, aDataSupplied );
[/code]
This piece of code returns an empty object, but I don't really get what you are trying to do here.
By the way as stated in the documentation 'fnAddData', should be able to handle an object.
But the first line in that method is this:
[code]if ( mData.length === 0 )
{
return [];
} [/code]
Thus you have to wrap the object in an array instead of just passing the object.
EDIT:
Event when I convert the object to an array, I still get the same error. So I'm guessing 'fnAddData' is conflicting with the use of aoColumns, could that be right? The error I get is this one: [quote]DataTables warning (table id = 'assignedUserGroupsTable'): Requested unknown parameter 'id' from the data source for row 1[/quote] in this method '_fnGetCellData'.
This discussion has been closed.
Replies
Allan
But I was using 'aoColumns', even though I didn't really need it, as apparently it is only for JSON conversion. At the moment everything works with everything client side.
If I wanted to start working with server-side processing for this datatable, how would I be able to add data to a datatable? In the documentation it is said that 'fnAddData' cannot be used together with server-side processing. Might this be due to the use of 'aoColumns'?
If you want to use server-side processing, and want to add data to the data set, you need to do it where the data set is - i.e. at the server. DataTables has no knowledge of the full data set when used in server-side processing mode (its really just a display and event handler). So you would add the row at the server and then simply call fnDraw to have the table redraw and show the updated data set.
Allan