How to update a single cell in table

How to update a single cell in table

ptmoyptmoy Posts: 2Questions: 0Answers: 0
edited March 2012 in General
In looked at the documentation, it seems like the only thing I can use is the function fnUpdate. But I'm a bit confused by what input parameters this function needs. Documentation says the 2nd parameter has to be: "{node|int}: TR element you want to update or aoData index." What is "node" and what is "aoData index"?

In any regards, here's what I'm really trying to do:

1) Load the initial dataset from a server (in JSON format) using AJAX.
2) Setup a websocket where the server can send unsolicited cell updates to the client when necessary.
3) Upon receiving the update from the server, use a Datatable function (or just jquery) to update the table.

Problem is how to identify the cell to update. The server knows which cell. But what information should it send in the update message to tell the client? This whole exercise is relatively easy if DataTables allows the server to pre-tag each row with an "ID" attribute when sending the initial data, or if one can configure DataTables to assign an "ID" to each table row somehow automatically. If this is possible, then the server can send the "ID" with each update. Does anyone know whether assigning an ID is possible? If not, does anyone have an idea on what the best way to do this?

Thanks in advance.

Replies

  • ptmoyptmoy Posts: 2Questions: 0Answers: 0
    I didn't look close enough at the documentation. As it turns out, adding an ID to rows appears to be fairly easy. I'll give it a try.

    I still have the questions regarding fnUpdate though. Can someone who know please post an answer to point me in the right direction?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > What is "node" and what is "aoData index"?

    node is the DOM element (i.e. what you get from document.getElementById('hello') or $('#hello')[0]).

    The aoData index is the DataTables internal index for the row - I'd ignore this one for now and use the node :-).

    fnUpdate requires you to know the row and the column index. The row is relatively simple with the ID (you can use DT_RowId to have it added automatically), however the column index might be a little harder, although not too difficult :-). There are lots of ways of getting the column index including fnGetPosition or $().index() or even your own loop with a counter.

    Allan
This discussion has been closed.