Server-side AJAX PHP: add an extra field

Server-side AJAX PHP: add an extra field

szakendreszakendre Posts: 24Questions: 10Answers: 0

Hello,

I use the datatable with PHP database backend.

JavaScript:

ajax:
{
    url: 'ajax/users.php',
    type: "POST",
    data: function ( d )
    {
        d.GLOBAL_userid = <?php print $_SESSION['usersid']; ?>;
    }
},
...
columns: [
{
    "data": "username"
},

PHP:

    $editor = Editor::inst( $db, 'users', 'id' )
    ->fields(
        Field::inst( 'username' ),

How can I add an extra column to this that doesn't come from database?

If I just make a new field it said: "Table part of the field was not found."

Thank you and best regards:
Endre, Szak

This question has accepted answers - jump to:

Answers

  • rf1234rf1234 Posts: 2,950Questions: 87Answers: 416
    Answer ✓

    Just alias an existing database column and return whatever you want. Just like in here: updaterName and creatorName are not in the database. Make sure to use ->set( false ) for the aliased columns.

    Field::inst( 'ctr_event.updater_id' ) ->set(Field::SET_BOTH)
                                          ->setValue( $_SESSION['id'] ),
    Field::inst( 'ctr_event.creator_id' ) ->set(Field::SET_CREATE)
                                          ->setValue( $_SESSION['id'] ),
    Field::inst( 'ctr_event.updater_id AS ctr_event.updaterName' )->set( false )
        ->getFormatter( function($val, $data, $opts) {
            return getUserName($val);
        }),                     
    Field::inst( 'ctr_event.creator_id AS ctr_event.creatorName' )->set( false )
        ->getFormatter( function($val, $data, $opts) {
            return getUserName($val);
        })   
    
  • szakendreszakendre Posts: 24Questions: 10Answers: 0

    It's not official yet, but you're a genius!
    Thank you! Mercy! Köszönöm! Danke Schön!
    How can I thank you?

  • rf1234rf1234 Posts: 2,950Questions: 87Answers: 416
    Answer ✓

    Just by writing what you wrote... Köszönöm for that. Greetings to Hungary. Haven't been to Budapest in a long time!

This discussion has been closed.