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

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

mauro218mauro218 Posts: 9Questions: 5Answers: 0
edited March 2015 in Editor

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();

<?php > ``` ?>

Thank you!

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

    What do you get back from the server if it is not valid JSON?

    Allan

  • mauro218mauro218 Posts: 9Questions: 5Answers: 0

    If I removed:
    ->options( 'Account', 'idAccount', 'AccountName' ),
    It works fine and it displays the account name correctly.

    Once I add it I get blank as returned.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    If there is nothing in the Ajax response, you'll probably need to check the HTTP server's error logs. That should have a message in it indicating what the issue is.

    Could you show me that message (assuming there is one - there should be!).

    Regards,
    Allan

This discussion has been closed.