Updating a table with an Ajax source

Updating a table with an Ajax source

jnedzeljnedzel Posts: 28Questions: 4Answers: 0
edited June 2012 in DataTables 1.9
I have a datable that is using an Ajax source. On the client side, I want to add another column when the table is created. I want to put a Javascript link in that column, so that when the user clicks on that link, a Javascript function will be called to delete the entity represented by that row.

I'm able to create the table with an extra column called "actions" and a null value. After the table is rendered, I try to update the cells using fnUpdate:

[code]var oTable = $("#gridTable").dataTable();
oTable.fnUpdate("Delete", 1, 1);[/code]

What is weird is that if I set a breakpoint in firebug and step through this, the edited text shows up in the cell. But if I remove the breakpoint, I get an error in the error console:

[code]Error: a.aoData[b] is undefined
Source File: http://localhost:8080/portal/media/data-tables-1.9.0/js/jquery.dataTables.min.js
Line: 29[/code]

Any ideas? Should I be using a different approach?

Replies

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    > I want to add another column when the table is created

    I'm afraid you can't at the moment - DataTables does not currently allow dynamic addition and deletion of columns from a table. The number of columns it has when initialised is the number it will have for its "lifetime".

    Allan
  • jnedzeljnedzel Posts: 28Questions: 4Answers: 0
    edited June 2012
    Allan:

    As I described above, I was able to define the table with the extra column -- two from my Ajax data source, and the third column is empty. I did that at table initialization. What I need to do now is edit the values in that third column. All I need to do is put javascript links in the cells in that third column.

    Is that really impossible to do? Isn't that the point of fnUpdate -- to update the value in a cell?

    Thanks,

    Jared
  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    > All I need to do is put javascript links in the cells in that third column.

    Oh I see - no that is perfectly possible - indeed there are a lot of ways to do it. The way I would recommend, and use in my own Editor examples, is to use sDefaultContent : http://editor.datatables.net/release/DataTables/extras/Editor/examples/inlineControls.html .

    Alternatively fnRender, mDataProp as a function, fnCreatedCell or fnCreatedRow could be used to do the same thing!

    Allan
  • jnedzeljnedzel Posts: 28Questions: 4Answers: 0
    Thanks for the pointers, I'll take a look.
This discussion has been closed.