Get Data from a Selected row the cell
Get Data from a Selected row the cell
bill_Tom
Posts: 19Questions: 4Answers: 0
Hello,
i like the value from a cell in a selected row, but it doesn't work.
I like to call the cell by the name, because later i need a hidden value which is not shown in the table - the id.
This is my code
columns: [
{ "data": "ks_rezept.ks_order_name" },
{ "data": "ks_status.ks_status_name" },
{ "data": "ks_auftrag_sammel.ks_Stueckzahl" },
{ "data": "ks_auftrag_sammel.ks_Gewicht_order" }
],
select: true,
lengthChange: false,
buttons: [ {
extend: 'selectedSingle',
text: 'Show Order Name'
action: function ( e, dt, node, config ) {
/var sdata = table.cell('.selected', 0).data(); -> this is working
var tdata = table.fnGetData('ks_rezept.ks_order_name');
alert (tdata) ;
}
Can anybody help me?
Thanks a lot,
Thomas
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The comment nots that this method (
cell().data()
) is working - but perhaps has only the data for that cell and not the whole row - which perhaps you need? The legacyfnGetData
method is not (which I would suggest ignoring since it is a legacy method).If you want the data for the whole row use:
Allan
Hello Allan,
sorry but I do not find any answers for my question in the documentation.
Now I take your code - It is working. I get the index of the row. Thx...
But now i like to print a value of a cell of the row.
I like only the surname - i tried it with
Where can i find an example, how it works? it can't be so difficult.
Thanks a lot,
Thomas
Simply:
data.surname
(assuming you are using an object).Allan
Hello Allan,
and here i have a small problem (maybe).
The name of the column is 'ks_order.ks_surname'
Because my datasource is a leftjoin (PHP) and so I have a dot in the column-name.
So must i rename the column as 'tbl_surname' or is there an other way?
If i will rename the column - how is the right way?
Thx,
Thomas
In which case you should be able to simply use
data.ks_order.ks_surname
.Adding
console.log( data );
will print the data out into your browser's console so you can inspect its structure.Allan
Hello Allan,
thanky for your reply. I have done it.
Now i see the structure, when i click on the 'object' in my browser console.
it looks like:
Now i like to the column 'data.ks_order.ks_surname' but i don't know how.
But It doesn't work - nothing happen.
Thx for your help.
Thomas
Does it work if you
console.log()
it? It might be that alert has been disabled for your page. Looking at the console trace you gave I can't see any reason why that data access wouldn't work...Hello Allan,
what do you mean with console.log() it?
I tried it now in chrome and mozilla it doesn't work.
The alert box works
alert (test)
and it doesn't work withalert ('1: ' + data.ks_order.ks_surname ) ;
What can I try? Thx a lot,
Thomas
Hello Allan,
find the Mistake.
It was a litte Bastart-Mistake... :-(
var data = table.row
was wrong - i writevar data = table.rows
Allan - Thanks a lot for your help!
Thomas