Value not showing up in table, but showing up in drop down box

Value not showing up in table, but showing up in drop down box

wilsonc91wilsonc91 Posts: 2Questions: 1Answers: 0

The drop box shows up when I click on the field, but doesn't show up in the table.

Link to dataTables debugger

Ex.
No value shown

But the drop down shows the correct value

Any ideas on whats causing this? The drop down boxes once I select them display the correct values but they aren't showing up on the table unless I click on them.

invoices.php

Editor::inst( $db, 'invoices' )
    ->fields(
        Field::inst( 'invoices.id' )->validator( 'Validate::notEmpty' )->validator( 'Validate::numeric' ),
        Field::inst( 'invoices.client_id')
            ->options( function () use ( $db ) {
                // Use `selectDistinct` to get the full list of names from the
                // database and then concatenate the first and last names
                $userList = $db->selectDistinct( 'contacts', 'id, first_name, last_name', null, 'last_name ASC' );
                $out = array();

                while ( $row = $userList->fetch() ) {
                    $out[] = array(
                        "value" => $row['id'],
                        "label" => $row['first_name'].' '.$row['last_name']
                    );
                }

                return $out;
            } ),
        Field::inst( 'contacts.first_name' ),
        Field::inst( 'contacts.last_name' ),
        Field::inst( 'invoices.description' ),
        Field::inst( 'invoices.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 )
    )
    ->leftJoin( 'contacts',     'contacts.id',          '=', 'invoices.client_id' )
    ->process( $_POST )
    ->json();

javascript

<script type="text/javascript" language="javascript" class="init">



        var editor; // use a global for the submit and return data rendering in the examples

        $(document).ready(function() {
            editor = new $.fn.dataTable.Editor( {
                ajax: "{{ URL::to('php/invoices.php') }}",
                table: "#example",
                fields: [ {
                    label: "Client Name:",
                    name: "invoices.client_id",
                    type:  "select"
                }, {
                    label: "Description:",
                    name: "invoices.description"
                }, {
                    label: "Start date:",
                    name: "invoices.date",
                    type: "date"
                }
                ]
            } );

            // Activate an inline edit on click of a table cell
            $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
                editor.inline( this );
            } );

            $('#example').DataTable( {
                dom: "Tfrtip",
                ajax: "{{ URL::to('php/invoices.php') }}",
                columns: [
                    { data: null, defaultContent: '', orderable: false },
                    { data: "invoices.id" },
                    {
                        data: "invoices.client_id",
                        render: function ( val, type, row ) {
                            return val.first_name ?
                            val.first_name +' '+ val.last_name :
                                    '';
                        },
                        defaultContent: ""
                    },
                    { data: "invoices.description" },
                    { data: "invoices.date" },
                ],
                order: [ 1, 'asc' ],
                tableTools: {
                    sRowSelect: "os",
                    sRowSelector: 'td:first-child',
                    aButtons: [
                        { sExtends: "editor_create", editor: editor },
                        { sExtends: "editor_edit",   editor: editor },
                        { sExtends: "editor_remove", editor: editor }
                    ]
                }
            } );
        } );

        </script>

Answers

  • wilsonc91wilsonc91 Posts: 2Questions: 1Answers: 0

    Figured it out.
    data: "invoices.client_id"
    should be
    data: "contacts",

    However, I can't get the drop box anymore to select the contact. Any idae?

This discussion has been closed.