fnUpdate doesn't seem to be working for me
fnUpdate doesn't seem to be working for me
I am trying to use fnUpdate to update a particular column of my table....trying to get around the mRender issue I was having with a second ajax call. This is a really scaled down test code just so I can see how to go about this...
$.ajax({
url:"data.php",
dataType:"json",
data:{
"action": action
},
success:function(data){
oTable = $('#example').dataTable( {
"bAutoWidth":false,
"bProcessing": true,
"bDestroy": true,
"aaData": data,
"aoColumns": [
{ "mData": "prg_guid" },
{ "mData": null,
"defaultContent":" ",
"sName": "ostatus"}
]
} );
$.each(data,function(i,v){
var sData = oTable.fnGetData(i,1); // I get the current row, 2nd column - which is undefined because of above definition
sData = "hi"+i; // just trying to set it with an example text
var succeed = oTable.fnUpdate(sData, i,1) // trying to update the current row, column 1 (2nd column) with the text I put in sData
var vData = oTable.fnGetData(i,1); // trying to see if anything is there
console.log(vData); // the value displayed is null
});
}
} );
I'm sure I am doing this wrong, so any guidance to make this simple test work would be greatly appreciated. I tried to see if I could upgrade to DataTables 1.10 but for right now, I can't, so I can't use your previous suggestion of setting it with the cell.data.
$.ajax({
url:"data.php",
dataType:"json",
data:{
"action": action
},
success:function(data){
oTable = $('#example').dataTable( {
"bAutoWidth":false,
"bProcessing": true,
"bDestroy": true,
"aaData": data,
"aoColumns": [
{ "mData": "prg_guid" },
{ "mData": null,
"defaultContent":" ",
"sName": "ostatus"}
]
} );
$.each(data,function(i,v){
var sData = oTable.fnGetData(i,1); // I get the current row, 2nd column - which is undefined because of above definition
sData = "hi"+i; // just trying to set it with an example text
var succeed = oTable.fnUpdate(sData, i,1) // trying to update the current row, column 1 (2nd column) with the text I put in sData
var vData = oTable.fnGetData(i,1); // trying to see if anything is there
console.log(vData); // the value displayed is null
});
}
} );
I'm sure I am doing this wrong, so any guidance to make this simple test work would be greatly appreciated. I tried to see if I could upgrade to DataTables 1.10 but for right now, I can't, so I can't use your previous suggestion of setting it with the cell.data.
This discussion has been closed.
Replies
Allan
I've refactored it into a trivial test case: http://live.datatables.net/vaveguk/1/edit . And that appears to work correctly.
The one thing that bothers me about your code the most (although I don't think it is the issue) is that you are using the array index `i` as the data index position in the table. I think you might get away with it here, by fluke. But generally you would want to loop over the nodes (using `oTable.fnGetNodes()` to get them) and then pass the row node into the other functions.
However, as I say, I think you might just happen to get away with it because of how your table is constructed, so there is something else going on. However, as you can see, I can't reproduce the error. To be able to offer any help, I'd need to be able to do so so I can debug it.
Allan
fnGetNodes will return all nodes for all rows. I'm guessing I shouldn't use the 'i' here either to give me just the current row, so I would get all rows of data with how ever many columns I have. When you say to loop through them do you mean using a 'for' loop? kind of like below?
$(document).ready( function () {
var oTable = $('#example').dataTable();
var nodes = oTable.fnGetNodes();
for (i=0; i