Quantcast
Channel: Editor — DataTables forums
Viewing all articles
Browse latest Browse all 3744

Can't get a select to work in Editor from server side

$
0
0

I'm trying to create a select for Rolodex.idAccountfield pulling AccountName from a MySQL database Account. I have followed the exact stepa showed in the examples:

https://editor.datatables.net/examples/advanced/deepObjects.html

Once I do the same steps I get: DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

My code:


        $(document).ready(function() {
            editor = new $.fn.dataTable.Editor( {
                ajax: "rolodex_DTS.php",
                table: "#example",
                fields: [ {
                    label: "First name:",
                    name: "Rolodex.FirstName"
                }, {
                    label: "Last name:",
                    name: "Rolodex.LastName"
                }, {
                    label: "Notes:",
                    name: "Rolodex.Notes"
                }, {
                    label: "Birthday:",
                    name: "Rolodex.Birthday",
                    type: "date"
                }, {
                    label: "Account:",
                    name: "Rolodex.idAccount",
                    type: "select"
                }, {
                    label: "Email Address:",
                    name: "EmailAddress.EmailAddress"
                }
                ]
            } );

<?php

// DataTables PHP library
include $_SERVER["DOCUMENT_ROOT"] . '/Editor-PHP-1.4.0/php/DataTables.php';

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Join,
    DataTables\Editor\Validate;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'Rolodex', 'idRolodex' )
    ->fields(
        Field::inst( 'Account.AccountName' ),
        Field::inst( 'Rolodex.idAccount' )
            ->options( 'Account', 'idAccount', 'AccountName' ),
        Field::inst( 'Rolodex.FirstName' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'Rolodex.LastName' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'Rolodex.Birthday' )
            ->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 )
    )
    ->leftJoin( 'Account', 'Account.idAccount', '=', 'Rolodex.idAccount' )
    ->leftJoin( 'EmailAddress', 'EmailAddress.idEmailAddress', '=', 'Rolodex.idEmailAddressMain' )
    ->process( $_POST )
    ->json();

?>

Thank you!


Viewing all articles
Browse latest Browse all 3744

Trending Articles