fill type:select with conditional data

fill type:select with conditional data

mfmf Posts: 41Questions: 11Answers: 0
edited August 2017 in Free community support

Hello all, I would like to know how I can populate a select field with conditional data,

But how can I do it in datatables? For example:

Editor::inst( $db, 'users' )
->field(
Field::inst( 'users.first_name' ),
Field::inst( 'users.last_name' ),
Field::inst( 'users.phone' ),
Field::inst( 'users.site' )
->options( Options::inst()
->table( 'sites' )
->value( 'id' )
->label( 'name' )
)
->validator( 'Validate::dbValues' ),
Field::inst( 'sites.name' )
)
->leftJoin( 'sites', 'sites.id', '=', 'users.site' )
->process($_POST)
->json();

Suppose table sites also had a column named visible, so I want to make a "where" condition on the joined table

According to the manual I can use this but where to put it ?
$editor->where( 'visible', 0 );

This question has an accepted answers - jump to answer

Answers

  • mfmf Posts: 41Questions: 11Answers: 0
    edited August 2017

    I have this now:

    `// Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'bezoekverslagen', 'bezoekverslagen_id' )
    ->fields(
    Field::inst( 'bezoekverslagen.dealernr' ),
    Field::inst( 'bezoekverslagen.beschrijving' ),
    Field::inst( 'bezoekverslagen.afspraak' ),
    Field::inst( 'bezoekverslagen.opvolgen' ),

        Field::inst( 'bezoekverslagen.gespreksonderwerp_id' )
            ->options( Options::inst()
                ->table( 'gespreksonderwerp' )
                ->value( 'gespreksonderwerp_id' )
                ->label( 'onderwerp' )
            ),
    
        Field::inst( 'gespreksonderwerp.onderwerp' ),
        Field::inst( 'bezoekverslagen.voltooid' )
            ->setFormatter( function ( $val, $data, $opts ) {
                return ! $val ? 0 : 1;
            } )
    )
    ->leftJoin( 'gespreksonderwerp', 'gespreksonderwerp.gespreksonderwerp_id', '=', 'bezoekverslagen.gespreksonderwerp_id' )
    ->where( 'gespreksonderwerp.zichtbaar', 0 )
    ->process( $_POST )
    ->json();`
    

    But I think this only filters what I see in the table and not what I can select when creating a new record. I hope someone can help, thanks!

  • rf1234rf1234 Posts: 2,986Questions: 87Answers: 421
    Answer ✓

    "But I think this only filters what I see in the table and not what I can select when creating a new record."

    You are exactly right!

    Just take a look at my first reply in this post and you should find everything you need including a little more complex rendering of the options. There is only one limitation: Your WHERE clause must be a closure function in options! (But only there fore everyhting else you can use the "normal" WHERE clause as above.)

    https://datatables.net/forums/discussion/comment/116681/#Comment_116681

    Prettig weekend!

  • mfmf Posts: 41Questions: 11Answers: 0

    Dear rf1234, that looks good! thanks I will try that.

    U ook prettig weekend!

This discussion has been closed.