Unable to fetch data from JOIN Table

Unable to fetch data from JOIN Table

CapamaniaCapamania Posts: 233Questions: 81Answers: 5
edited August 2016 in Editor

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:

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    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

  • CapamaniaCapamania Posts: 233Questions: 81Answers: 5
    edited August 2016

    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

  • CapamaniaCapamania Posts: 233Questions: 81Answers: 5
    edited August 2016 Answer ✓

    Allllright. Doing it in 2 steps did the magic!

    // getting the rows data
    var data = table.row( this ).data();
    
    // 1. get the values from object table_01
    var getRow = data[ 'table_01' ];
    
    // 2. get the desired values of the object table_01     
    var getValue01 = getRow[ 'value01' ];       
    var getValue02 = getRow[ 'value02' ];
    

    Wuuupwup!!

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Nice one - good to hear you have a solution and thanks for posting back.

    Allan

This discussion has been closed.