DataTables Editor IF statement

DataTables Editor IF statement

LeeMcLeeMc Posts: 1Questions: 1Answers: 0

Is it possible to do a MySQL IF statement in the editor?

For example:

Editor::inst( $db, 'todo' )
    ->fields(
        Field::inst( 'Column1' ),
        Field::inst( 'Column2' ),
        Field::inst( 'IF(Column3 = 0, Column4, Column3)' )
    )
    ->process( $_POST )
    ->json();

I've tried it but get a SQL error message so wonder if there is another way.
I'd also like to be able to sort / search by it.

Answers

  • allanallan Posts: 62,333Questions: 1Answers: 10,228 Site admin

    You could create a VIEW and read from that which would work just fine.

    Other option is to read both column3 and column4 and then use a renderer (columns.render) on the client-side to conditionally render which one you want.

    Allan

This discussion has been closed.