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

Possibility to save 2 different values in Database with 1 checkbox

$
0
0

Hi there,
Has one of you already experience with the following situation?

I would like to save a value with a checkbox in two different DB tables, e.g.
1. DB table bookings -> value status = "new" or "canceled"
2. DB table rooms -> value storno = 0 or 1

I can save in table rooms the value storno = 0 or 1 with the following code but
how can I additionally store the value status = "new" or "canceled" in the bookings table?

JS

var editor; // use a global for the submit and return data rendering in the examples
(function($) {
    $(document).ready(function() {
        editor = new $.fn.dataTable.Editor({
            ajax: '/php/table.bookings_test.php',
            table: '#bookings_test',
            fields: [
            {
                label:     "Storno:",
                name:      "rooms.ca_storno",
                type:      "checkbox",
                separator: "|",
                options:   [
                    { label: '', value: 1 }
                ]
            }]
        });
        
        var table = $('#bookings_test').DataTable({
            ajax: '/php/table.bookings_test.php',
            Processing: true,
            ServerSide: true,
            "lengthMenu": [[10, 20, 50, -1], [10, 20, 50, "alle"]],
            "pageLength": 20,
            columns: [
                {
                    data:   "rooms.ca_storno",
                    render: function ( data, type, row ) {
                        if ( type === 'display' ) {
                            return '<input type="checkbox" class="storno">';
                        }
                        return data;
                    },
                    className: "dt-body-center"
                }
            ],
            rowCallback: function ( row, data ) {
                // Set the checked state of the checkbox in the table
                $('input.storno', row).prop( 'checked', data.rooms.ca_storno == 1 );
            },
            responsive: true,
            columnDefs: [
                { type: 'date-eu', targets: 0 },
                { type: 'date-eu', targets: 10 }
            ]
        });
        $('#bookings_test').on( 'change', 'input.storno', function () {
            editor
                .edit( $(this).closest('tr'), false )
                .set( 'rooms.ca_storno', $(this).prop( 'checked' ) ? 1 : 0 )
                .submit();
        } );
    });
}(jQuery));

PHP

// DataTables PHP library and database connection
include( "lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

Editor::inst( $db, 'rooms', 'uid' )
    ->field( 
        Field::inst( 'rooms.ca_storno' )
            ->setFormatter( function ( $val, $data, $opts ) {
                return ! $val ? 0 : 1;
            } )
    )
    ->process($_POST)
    ->json();

BR


Viewing all articles
Browse latest Browse all 82387

Trending Articles



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