Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82037

Table not updating when adding new row / editing row with custom primary key

$
0
0

I'm using Editor 1.6 and Datatables and have a very simple table / source. Using PHP and server side. I have used the Editor::new and specified the primary key (which is not auto-increment, its a unique serial number) in the third parameter according to the docs.

When I add a new row via the Editor pop-up, the new row is not shown and debugging shows an empty data[] returned. When I edit a row, it updates fine as long as I don't touch the primary key field. Relevant code segments below. Hopefully this is something easily fixed. I don't need an extra "id" field in the table since the umpid field is always unique.

Editor::inst( $db , 'hardware', 'umpid')
    ->field(
        Field::inst( 'hardware.name' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'hardware.wifi_mac' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'hardware.wired_mac' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'hardware.serialnum' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'hardware.umpid' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'hardware.notes' ),
        Field::inst( 'hardware.updated')
            ->setValue( date('Y-m-d H:i:s') ),
        Field::inst( 'hardware.updated_by' )
            ->setValue( $_SESSION['display_name'] )
    )
    ->process($_POST)
    ->json();
var editor; // use a global for the submit and return data rendering in the examples

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: "ajax_hardware_data.php",
        table: "#hardwareData",
        fields: [ {
                label: "Name:",
                name: "hardware.name"
            }, {
                label: "WiFi Address (MAC):",
                name: "hardware.wifi_mac"
            }, {
                label: "Ethernet Address (MAC)",
                name: "hardware.wired_mac"
            }, {
                label: "Serial Number:",
                name: "hardware.serialnum"
            }, {
                label: "UM Property ID#",
                name: "hardware.umpid"
            },{
                label: "Notes:",
                name: "hardware.notes"
            }
        ]
    } );

    $('#hardwareData').DataTable( {
        dom: "lBfrtipl",
        ajax: {
            url: "ajax_hardware_data.php",
            type: 'POST'
        },
        columns: [
            { data: "hardware.name" },
            { data: "hardware.wifi_mac" },
            { data: "hardware.wired_mac" },
            { data: "hardware.serialnum" },
            { data: "hardware.umpid" },
            { data: "hardware.notes" }
            ],
        select: true,
        "lengthMenu": [ [20, 25, 50, -1], [20, 25, 50, "All"] ],
        buttons: [
        <?php if (chkgrp("IT Staff")) : ?>
            { extend: "create", editor: editor },
            { extend: "remove", editor: editor },
        <?php endif; ?>
            { extend: "edit",   editor: editor }
        ]
    } );

} );

Viewing all articles
Browse latest Browse all 82037

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>