Getting a join table to update using Editor

Getting a join table to update using Editor

webpointzwebpointz Posts: 126Questions: 30Answers: 4
edited July 2016 in Editor

Hi Allan,

Thanks for your help so far. I have managed to get everything working EXCEPT the inline/editor update for a joined table.
(see https://datatables.net/forums/discussion/36350/). Apologies but in trying to display my code, editing caused multiple windows to keep adding to the thread).

Here's my code:

PHP

include( "lib/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, 'kit_inventory', 'kit_inventory_id' )
    ->fields(
Field::inst( 'kit_inventory_items.kit_items_id' ),
        Field::inst( 'kit_items.kit_items_name' ),
        Field::inst( 'kit_inventory_items.kit_inventory_items_serial_number' )
    )

    ->leftJoin( 'kit_inventory_item_history', 'kit_inventory_item_history.kit_inventory_id', '=', 'kit_inventory.kit_inventory_id' )            
    ->leftJoin( 'kit_inventory_items', 'kit_inventory_items.kit_inventory_items_id', '=', 'kit_inventory_item_history.kit_inventory_items_id' )
    ->leftJoin( 'kit_items', 'kit_items.kit_items_id', '=', 'kit_inventory_items.kit_items_id' )
    ->leftJoin( 'kit_inventory_items_status', 'kit_inventory_items_status.kit_inventory_items_status_id', '=', 'kit_inventory_items.kit_inventory_items_status_id' )
    ->where( 'kit_inventory.kit_inventory_id', $_GET['thisinv'] )
    ->process($_POST)
    ->json();

JS:

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

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: "../php/table.seh_kit_contents.php?thisinv=<?php echo $inventoryid; ?>",
        table: "#example",
        fields: [ 
{
    
                name: "kit_inventory_items.kit_items_id",
                                type:  "hidden"
              },
                          {
                label: "Name:",
                name: "kit_items.kit_items_name",
                                type:  "readonly"
              },{
                 label: "Serial Number:",
                 name: "kit_inventory_items.kit_inventory_items_serial_number"
              }
        ]
    } );

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

    $('#example').DataTable( {
        dom: "Tfrtip",
        ajax: "../php/table.seh_kit_contents.php?thisinv=<?php echo $inventoryid; ?>",
        columns: [
            {
                data: null,
                defaultContent: '',
                className: 'select-checkbox',
                orderable: false
            },
    { data: "kit_items.kit_items_name" },
            { data: "kit_inventory_items.kit_inventory_items_serial_number" }
        ],
        order: [ 0, 'asc' ],
                bPaginate : false,
                bFilter : false,
                language: { infoFiltered: ""},   
        tableTools: {
            sRowSelect: "os",
            sRowSelector: 'td:first-child',
            aButtons: [
                { sExtends: "editor_edit",   editor: editor }
            ]
        }
    } );
} );

I don't know how to get the SERIAL NUMBER that's in the "kit_inventory_items" table to update with hidden fields when the main table in the PHP code is the "kit_inventory" table with a primary id of "kit_inventory_id".

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • webpointzwebpointz Posts: 126Questions: 30Answers: 4

    Also, using Firefox Inspector, I notice in the JSON response that every Object (0-13) has the same value for DT_RowId.

    data:Array
    0: Object
    DT_RowId: "row_3"

  • allanallan Posts: 63,516Questions: 1Answers: 10,473 Site admin
    edited July 2016 Answer ✓

    Is this basically a continuation of the same discussion? Let's keep going with the other thread rather than spreading it over multiple points.

    Allan

This discussion has been closed.