fnUpdate - how to update a single cell when the original data is an array?

fnUpdate - how to update a single cell when the original data is an array?

nunonuno Posts: 14Questions: 0Answers: 0
edited April 2012 in General
I've built a table with data looking like:

[ [["f7bc04fd5473e9bb3916f8181acc90a7", "ACCEPT"], 2, 0, 0, 0],
[["68f233bfe0b220c40ea6bb90abfb4773", "AEO"], 4, 1, 0, 0].
...
]

The table is built with values 'ACCEPT' and 'AEO' being displayed in the first column as specified by fnRender:

'aoColumns': [
{"sTitle": "Project",
"fnRender": function(obj) {
return obj.aData[ obj.iDataColumn ][1]
}

The values "f7bc04fd5473e9bb3916f8181acc90a7" and "68f233bfe0b220c40ea6bb90abfb4773" are used to give the table row an id by calling fnCreatedRow:


"fnCreatedRow": function( nRow, aData, iDataIndex ) {
if(project_user_roles[iDataIndex][0][0]=='unassigned'){
j(nRow).attr('id','unassigned').addClass('row_selected')
}else {
j(nRow).attr('id',project_user_roles[iDataIndex][0][0]+','+userid)
}
return nRow
}


I would like to be able to update a row's first cell. I tried using fnUpdate but if I pass it a string it will render it's 2nd character in the cell:

return obj.aData[ obj.iDataColumn ][1]

So I tried passing a complete array even if I only wanted to update a single cell:

oTable.fnUpdate([['1234','test'],1,0,0,0],0,0)

This however is failing with a "TypeError: a.replace is not a function".


Not sure what the problem is! Any ideas?

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    If you are updating an individual cell, just pass in the data for that cell only (i.e. you might have fnUpdate('1234', 0, 0)).

    Having said that, the error you are getting is slightly surprising - does it say what line on the unminified code that is occurring on?

    Allan
  • nunonuno Posts: 14Questions: 0Answers: 0
    I have solved the problem by changing my data format from an array to a hash. It now looks like:

    Object { DT_RowId="f7bc04fd5473e9bb3916f8181acc90a7,227", 0="ACCEPT", 1=2, more...}

    By setting the DT_RowId key the table row gets assigned automatically and I can get rid off the
    fnRender call and the fnCreatedRow callback.

    fnUpdate now works with a simple string.
  • nunonuno Posts: 14Questions: 0Answers: 0
    Hi Allan, just saw your comment. Thanks for looking at this. I was using the minified code so don't know the line...

    Anyway, the problem was that on my original data array the first value was an array:
    ["f7bc04fd5473e9bb3916f8181acc90a7", "ACCEPT"]
    I would then use fnRender to process it.

    So even if I was updating a single cell I needed to pass an array! The fnUpdate doesn't accept an array for updating a single cell. I tried passing a complete array containing the whole row data but that didn't work though.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Hmmm - that's an interesting one! DataTables is seeing that you are passing an array, and thus thinking that you are working with a whole row. I think I might need to rearrange the logic in fnUpdate a bit to cope with this - I've bookmarked this thread so I can give it some proper thought and the implications on the API :-)

    Thanks,
    Allan
This discussion has been closed.