how to get values?
how to get values?
first of all sorry but I'm a beginner in javascript and maybe this question is not relevant. So I'm having the following code and I would like to get my variables to send it with ajax to php, but I don't really understand how the positions are set it up.
[code]
var oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": 'arrays.txt',
"fnDrawCallback": function() {
$('#example td').click( function () {
/* Get the position of the current data from the node */
var aPos = oTable.fnGetPosition( this );
/* Get the data array for this row */
var aData = oTable.fnGetData( this.parentNode );
/* Update the data array and return the value */
var serverID =aData[ this should be the selected row first cell value ];
var db =aData[ this should be the selected row second cell value ];
var task =aData[ this should be the selected cell columns value ];
aData[ aPos[1] ] = 'clicked';
this.innerHTML = 'clicked';
} );
}
} );
} );
[/code]
thanks
fefe
[code]
var oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": 'arrays.txt',
"fnDrawCallback": function() {
$('#example td').click( function () {
/* Get the position of the current data from the node */
var aPos = oTable.fnGetPosition( this );
/* Get the data array for this row */
var aData = oTable.fnGetData( this.parentNode );
/* Update the data array and return the value */
var serverID =aData[ this should be the selected row first cell value ];
var db =aData[ this should be the selected row second cell value ];
var task =aData[ this should be the selected cell columns value ];
aData[ aPos[1] ] = 'clicked';
this.innerHTML = 'clicked';
} );
}
} );
} );
[/code]
thanks
fefe
This discussion has been closed.
Replies
You have to do something like this
var serverID =aData[ 0 ];
var db =aData[ 1 ];
var task =aData[ 2 ];
you could then use those variables in your ajax request. The reason the items are numerically indexed is because the oTable.fnGetData( this.parentNode ) will return an array. you can read more about javascript arrays here: http://www.echoecho.com/javascript10.htm
One thing to keep in mind is arrays are 0 based which means to get the first element of an array the key is always 0 and not 1, the key of 1 returns the second element in the array.
let say I'm having the following array with vallues in aData["valui1","value2","value3","value4","value5"]
and array aPos contains the index of the selected row and column .
if I'm selecting value2 from the first row than my array should look like [0,1]
or maybe I understood wrong. Actually in case of the colum I would like to get back as string the title of .
However, I would be tempted to architect it a little bit differently. Without seeing exactly what your end goal is, I couldn't make an intelligent suggestion; however, I can't help suspecting that instead of calling .click() from inside the row callback, you might be better off laying the "foundations" for the click in the fnRowCallback and then set your click event with a .delegate() call that will bind all present and future clicks at once.
thanks