Unable to fetch data from JOIN Table
Unable to fetch data from JOIN Table
I'm not able to fetch data from a Join Table. When console.log(getValue01); console.log(getValue02); I'm getting 'undefined':
In Console:
undefined
undefined
DT_RowId "row_29"
+table_01 Object { value_01="US", value_02="Wilmington", more...}
+table_02 Object { value_03="1", value_04="Test", more...}
That's my setup:
table = $('#mytable').DataTable( {
dom: "Blfrtip",
ajax: {
url: "source.php",
type: "POST"
serverSide: true,
columns: [
{ data: "table_01.value_01",
"render": function ( data, type, row ) {
return '<a href="/'+row.table_01.value_02+'.html">'+data+'</a>';
} },
{ data: "table_01.value_02",
"render": function ( data, type, row ) {
return '<a href="/'+data+'.html">'+data+'</a>';
} },
{ data: "table_02.value_03" },
{ data: "table_02.value_04" }
{
data: null,
"render": function ( data, type, row ) {
return '<a href="" class="button" role="button">Button</a>';
}
}
]
...
} );
// Fetching Data:
var button_inTable_table = $('#mytable').on('click', 'a.button', function (e) {
var data = table.row( this ).data();
var getValue01 = data[ 'table_01.value_01' ];
var getValue02 = data[ 'table_01.value_02' ];
console.log(getValue01);
console.log(getValue02);
console.log(data);
} );
With data from one table it's working fine, but with a JOIN table I'm getting undefined. Does anybody see why?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
You probably need to use the
columns.editField
option. However, I'm not actually seeing where you call Editor in the above, so I'm not certain what the issue is I'm afraid. Could you post your full code please?Allan
Thanks Allan. I did indeed not call the Editor instance for that table correctly. Now edit to the target table (table_03 / for mm relation) works.
But I'm still not able to predefine the values in the edit form.
```
// getting data of row works:
var data = table.row( this ).data();
// in console:
Object { DT_RowId="row_29", table_01={...}, table_02={...}}
+table_01 Object { value_01="US", value_02="Wilmington", more...}
+table_02 Object { value_03="1", value_04="Test", more...}
// getting targeted values is failing though (from JOIN table):
var getValue01 = data[ 'table_01.value_01' ];
var getValue02 = data[ 'table_01.value_02' ];
// In console:
undefined
undefined
Allllright. Doing it in 2 steps did the magic!
Wuuupwup!!
Nice one - good to hear you have a solution and thanks for posting back.
Allan