can't get data from row

can't get data from row

chucke1992chucke1992 Posts: 8Questions: 0Answers: 0
edited March 2014 in DataTables 1.9
When I click on a row - I add class info to it.
[code]$("#roletable tbody").click(function(event) {
$(oTable2.fnSettings().aoData).each(function() {
$(this.nTr).removeClass('info');
});
$(event.target.parentNode).addClass('info');
});
[/code]

I want to pass values from selected row(it is always only one row) to modal form when I click on [quote]rolesedit[/quote] button.
I was trying to do like this(I check each row and in order to check data I show alert)
[code]$("#rolesedit").click(function() {
var arr = oTable1.fnGetNodes();
var item = null;
for(var i = 0; i < arr.length; i++) {
if ($(arr[i]).hasClass('info')){
item = oTable1.fnGetData(arr[i]);
alert(item[0]);
}
}
$('#ErolenameInput').val(item[0]);
$('#ERoleID').val(item[1]);
});
[/code]
But item[0] is always undefined.
I was trying something like this too
[code]
$(oTable1.fnSettings().aoData).each(function() {
if ($(this.nTr).hasClass('info'))
alert('has class' + oTable1.fnGetData(this.nTr)[0]);
});[/code]
but it undefined too.

What is the correct way to get data?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Just use fnGetData to get the data for a row :-). I would suggest that the fnSettings object should _never_ be used externally unless you are _very_ familiar with how DataTables works internally. Also the settings object can and will change between releases.

    Your second clock block looks more correct. `item[0]` will be undefined if you are using an object data source. Are you?

    Allan
  • chucke1992chucke1992 Posts: 8Questions: 0Answers: 0
    [quote]will be undefined if you are using an object data source. Are you?[/quote]

    Yes, I use ajax data source - response from server in json with serialized to json object using GSON.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    In which case, just access the object properties as you normally would since fnGetData gives the original data object.

    Allan
  • chucke1992chucke1992 Posts: 8Questions: 0Answers: 0
    [quote]In which case, just access the object properties as you normally would since fnGetData gives the original data object.[/quote]

    Oh. I see. Thanks.
This discussion has been closed.