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?
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?
[ [["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?
This discussion has been closed.
Replies
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
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.
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.
Thanks,
Allan