createdRow with leftJoin

createdRow with leftJoin

Tony STony S Posts: 26Questions: 4Answers: 0
edited July 2019 in Free community support

Hello,
I can not recover the data as soon as I use left join with createdRow, which method should I use ?

$(document).ready(function() {
    $('#example').DataTable( {
        "createdRow": function ( row, data, index ) {
            if ( data[5] < 1 ) {
                $('td', row).eq(5).css('background-color', 'red');
            }
        }
    } );
} );

Answers

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    You haven't provided enough information to understand the problem.

    What happens when using the left join?

    What is different between the data when using the left join and not using the left join?

    Without being able to see the data and the issue we won't be able to help with suggestions. Please post a link to your page for troubleshooting. If you can't do that then maybe the developers can help by looking at the debug info collected using the debugger.

    Kevin

  • Tony STony S Posts: 26Questions: 4Answers: 0

    When I use a normal table this function works properly but when I use Table aliases I can not recover the data, it marks me (undefined) in the chrome console.

    In this example it's ok :

    Editor::inst( $db, 'users' )
        ->field(
            Field::inst( 'name' ),
            Field::inst( 'price' )
    )
    
    $(document).ready(function() {
        $('#example').DataTable( {
            "createdRow": function ( row, data, index ) {
                if ( data[2] < 1 ) {
                    $('td', row).eq(2).css('background-color', 'red');
                }
            }
        } );
    } );
    

    In this example the answer always undefined :

    Editor::inst( $db, 'users' )
        ->field(
            Field::inst( 'users.name' ),
            Field::inst( 'users.price' )
            Field::inst( 'users.pay_users' )
        )
        ->leftJoin( 'pay', 'pay.id', '=', 'users', 'users.pay' )
    
    
    $(document).ready(function() {
        $('#example').DataTable( {
            "createdRow": function ( row, data, index ) {
                if ( data[2] < 1 ) {
                    $('td', row).eq(2).css('background-color', 'red');
                }
            }
        } );
    } );
    
    
    $(document).ready(function() {
        $('#example').DataTable( {
            "createdRow": function ( row, data, index ) {
                if ( data['price'] < 1 ) {
                    $('td', row).eq(2).css('background-color', 'red');
                }
            }
        } );
    } );
    
    
    $(document).ready(function() {
        $('#example').DataTable( {
            "createdRow": function ( row, data, index ) {
                if ( data['users.price'] < 1 ) {
                    $('td', row).eq(2).css('background-color', 'red');
                }
            }
        } );
    } );
    

    In this situation how to recover ( data [2] ) ?

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    I don't use the PHP libraries so I'm not sure exactly what is returned with your left join. This example may help:
    https://editor.datatables.net/examples/advanced/joinSelf.html

    Based on what you posted it looks like you might have Datatabels configured for arrays but I think you might want to use objects. You can use the browser's developer tools to verify what is in the JSON response.

    If this doesn't help then someone more experienced with the PHP libraries will need to help. Or you can post an example of the JSON response.

    Kevin

  • Tony STony S Posts: 26Questions: 4Answers: 0

    Thank you Kevin, no it does not fit, .I am not strong in javascript, knowing that createdRow does not update after changing the line, is there an automatic refresh function without reloading the page?

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    no it does not fit

    Sorry, not clear what you mean.

    knowing that createdRow does not update after changing the line

    If you are updating the table data you can use rowCallback which will run each time the table is drawn.

    is there an automatic refresh function without reloading the page

    I'm guessing you are using ajax. In this case you can use ajax.reload() to have Datatables refresh the Datatable by fetching the data.

    Kevin

  • Tony STony S Posts: 26Questions: 4Answers: 0

    Ok thank you Kevin

This discussion has been closed.