Create/update DB table column from two fields

Create/update DB table column from two fields

peterbrownepeterbrowne Posts: 247Questions: 40Answers: 0

I want to set table a column week.week_full_name value based on the values of two fields, week.week and unit_group.unit_group.

var editor = new $.fn.dataTable.Editor( {
                ajax: "program_data/week_data.php",
                table: "#week_table",
                template: '#week_form',
                fields: [ {
                    label: "Week:",
                    name: "week.week"
                }, {
                    label: "Week Full Name:",
                    name: "week.week_full_name"
                }, {
                    label: "Unit Group:",
                    name: "week.unit_group_fk",
                    type: "select",
                    placeholder: "Select Unit Group..."
                } ]
            });
            

            var table = $( '#week_table' ).DataTable( {
                responsive: true,
                columnDefs: [ {
                    targets: [1],
                    render: $.fn.dataTable.render.ellipsis( 100, true )
                } ],
                ajax: "program_data/week_data.php",
                dom: "Bfrtip",
                columns: [ {
                    data: "week.week"
                }, {
                    data: "week.week_full_name"
                }, {
                    data: "unit_group.unit_group"
                }, {
                    data: "week.modified"
                }, {
                    data: "week.modified_by"
                } ],
                select: {
                    style: 'os',
                    selector: 'td:first-child'
                },
                buttons: []
            } );

Answers

  • peterbrownepeterbrowne Posts: 247Questions: 40Answers: 0

    Server side I have tried the following but not working...

    Editor::inst( $db_cm_dopt, 'week', 'week_pk' )->fields(
            Field::inst( 'week.week' ),
            Field::inst( 'week.week_full_name' )->setFormatter( function($val, $data, $field) {return $data['week.week'] . ' - ' . $data['unit_group.unit_group'];}),
            Field::inst( 'week.modified' ),
            Field::inst( 'week.modified_by' )->setValue( $user),
            Field::inst( 'week.unit_group_fk' )
                ->options( Options::inst()
                    ->table( 'unit_group' )
                    ->value( 'unit_group_pk' )
                    ->label( 'unit_group' )
                    ->where( function ($q) {
                $q->where( 'unit_group.type', 'learning_event' );
                    })
                ),
            Field::inst( 'unit_group.unit_group' )  
        )
         ->leftJoin( 'unit_group', 'unit_group.unit_group_pk', '=', 'week.unit_group_fk' )
        ->process($_POST)
        ->json();
    
  • allanallan Posts: 54,714Questions: 1Answers: 8,560 Site admin

    The data is submitted as 2D arrays, so

    $data['week.week']
    $data['unit_group.unit_group']
    

    should be:

    $data['week']['week']
    $data['unit_group']['unit_group']
    

    Respectively,
    Allan

Sign In or Register to comment.