fnAddData not working with object

fnAddData not working with object

EphEph Posts: 3Questions: 0Answers: 0
edited June 2012 in Bug reports
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'.

Replies

  • allanallan Posts: 61,908Questions: 1Answers: 10,148 Site admin
    Can you give me a link to a test page showing the problem please? The code you highlight in _fnAddData is taking a clone of the data you pass in, so DataTables doesn't modify the original data.

    Allan
  • EphEph Posts: 3Questions: 0Answers: 0
    I can't really post it somewhere publicly.

    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'?
  • allanallan Posts: 61,908Questions: 1Answers: 10,148 Site admin
    > 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
  • EphEph Posts: 3Questions: 0Answers: 0
    I know have two datatables and by using two buttons you can remove a row from one table and add it to another. At the moment this is completely client-side. I might will want to change this in the future. But as 'fnAddData' does not work with server-side processing, I should have to do an ajax call to remove and add a row and then reload the whole table. This will not really be the most efficient way of handling this right?
This discussion has been closed.