$columns = array( vs. Editor::inst( $db, 'datatables_demo' )

$columns = array( vs. Editor::inst( $db, 'datatables_demo' )

ScottSchmidtScottSchmidt Posts: 38Questions: 5Answers: 0

I do not understand the difference between $columns = array versus Editor::inst( $db, 'datatables_demo' ).
I keep seeing both frequently and both work with the database columns. I generally rarely see both at the same time?

$columns = array(
    array( 'db' => 'first_name', 'dt' => 0 ),
    array( 'db' => 'last_name',  'dt' => 1 ),
    array( 'db' => 'position',   'dt' => 2 ),
    array( 'db' => 'office',     'dt' => 3 ),
    array(
        'db'        => 'start_date',
        'dt'        => 4,
        'formatter' => function( $d, $row ) {
            return date( 'jS M y', strtotime($d));
        }
    ),
    array(
        'db'        => 'salary',
        'dt'        => 5,
        'formatter' => function( $d, $row ) {
            return '$'.number_format($d);
        }
    )
);

Source: https://datatables.net/examples/server_side/simple.html

// Build our Editor instance and process the data coming from _POST
'''Editor::inst( $db, 'datatables_demo' )
    ->fields(
        Field::inst( 'first_name' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'last_name' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'position' ),
        Field::inst( 'email' ),
        Field::inst( 'office' ),
        Field::inst( 'extn' )->validator( 'Validate::numeric' ),
        Field::inst( 'age' )->validator( 'Validate::numeric' ),
        Field::inst( 'salary' )->validator( 'Validate::numeric' ),
        Field::inst( 'start_date' )
            ->validator( 'Validate::dateFormat', array(
                "format"  => Format::DATE_ISO_8601,
                "message" => "Please enter a date in the format yyyy-mm-dd"
            ) )
            ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
            ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 )
    )

Source: https://datatables.net/forums/discussion/29568/is-this-this-the-staff-php-file-and-how-do-i-run-it-on-wamp
https://editor.datatables.net/manual/php/getting-started

Replies

  • ScottSchmidtScottSchmidt Posts: 38Questions: 5Answers: 0

    I just realized that:

    array versus Editor::inst( $db, 'datatables_demo' ) is probably using php/datatables with editor package;

    while
    $columns is probably the normal way? (without using the PHP library?)

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Spot on. Different libraries, with different setups!

    Allan

This discussion has been closed.