how to get values?

how to get values?

fefefefe Posts: 8Questions: 0Answers: 0
edited October 2011 in General
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

Replies

  • jcrawfordjcrawford Posts: 172Questions: 0Answers: 0
    fefe,

    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.
  • fefefefe Posts: 8Questions: 0Answers: 0
    I understand the concept of 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 .
  • GregPGregP Posts: 500Questions: 10Answers: 0
    edited October 2011
    I put my click binders into the fnRowCallback rather than the fnDrawCallback. And then since you're dealing with only the row, jcrawford's suggestion is the right starting point.

    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.
  • fefefefe Posts: 8Questions: 0Answers: 0
    so I'm retrieving back thru ajax datas to my table than I should evaluate each columns values if they are conform or not to the criteria s, in case if not than those values should be highlighted and should be able to make another ajax request. Than I have to pick up some parameters to make the call, this are the first, second rows and the column value where the call was requested. I just took a look on your suggestion and seems to cover what I would like to achieve and also the idea it sound better, I'm quite beginner in javascript so every idea would be appreciated.

    thanks
This discussion has been closed.