Sneaking rows into a data table

Sneaking rows into a data table

madlamadla Posts: 3Questions: 0Answers: 0
edited September 2012 in General
I'm working with a given table system (server controlled) that uses ajax to update,insert and delete rows of a couple of tables.

I added dataTables to add sorting and a range of other great features but ran into an issue with sorting after ajax updates.
The current table system feeds entire ... code snippets into the table and does updates all by itself without using datatables API.

After an update with the current table system, when I sort the table the update disappears (not surprising because the underlying data structure knows nothing about that update).

I thought I could just use fnAddData(row, false) to add the row to the underlying data structure without redrawing, but it looses all the row and cell classes/ids and such and throws a warning: DataTables warning (table id = 'campaignResults'): Requested unknown parameter '1' from the data source for row 7


So how can I work around this?

Thanks...martin

Replies

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin
    Can you link us to a test case showing the problem please? I don't quite understand. Also, are you using server-side processing, or client-side processing?

    Allan
  • madlamadla Posts: 3Questions: 0Answers: 0
    Not sure what I'm using ;-). Unfortunately this doesn't exist in the wild.

    The current system works is in essence CRUD on data in nested tables:

    User chooses to do add an item to a table. A form appears. User enters information and saved. All this happens via AJAX. When the save request returns, it sends back a JSON object that contains information what table to e.g. add this item too, and an Table row as an HTML snippet. e.g. some data....
    With javascript that TR is added at the top of the table.

    Works the same way with updates and deletes.

    When the Row get's added like this, obviously, it's not in the datamodel that datatables has established.
    Ideally if I could tell the datamodel to update itself based on the HTML that is now in the table, I would be done and sorting and such would work properly again.

    I looked at tableSorter, a much simpler solution, and it has a $('table').trigger('update') call, that seems to do the trick...but I'd much rather use dataTables with all it's features for some other parts to this project.

    As I can't seem to find a similar update call, I tried to look for other ways to accomplish it with dataTables. I played around with adding the row without changing the view after an add happened by triggering fnAddData([row], false) where row is the TR snippet. It appears to update the data model, but all the classes on the TR and internal TDs are gone.

    Does that explain it better?

    Thanks...martin
This discussion has been closed.