I want to change the field value of pregroupdata.status before datatable read from database. I use preGet event to implement. But it is not work.
There is my code.
<?php
header("Conten-Type:text/html;charset=utf-8");
/*
* Example PHP implementation used for the index.html example
*/
// DataTables PHP library
include( "../../php/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;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'pregroupdata' )
->fields(
Field::inst( 'pregroupdata.appdate' ),
Field::inst( 'pregroupdata.status' )->set(Field::SET_BOTH),
Field::inst( 'pregroupdata.setupdate' ),
Field::inst( 'pregroupdata.pastoralid' )->validator ( 'Validate::notEmpty' )
->options ( Options::inst()
->table( 'pastoral' )
->value( 'id' )
->label( 'name' )
),
Field::inst( 'pname.name' ),
Field::inst( 'pregroupdata.zoneid' )->validator ( 'Validate::notEmpty' )
->options ( Options::inst()
->table( 'zonedata' )
->value( 'id' )
->label( 'name' )
),
Field::inst( 'zname.name' ),
Field::inst( 'pregroupdata.leaderid' )->validator ( 'Validate::notEmpty' )
->options ( Options::inst()
->table( 'leader' )
->value( 'id' )
->label( 'name' )
),
Field::inst( 'lname.name' ),
Field::inst( 'lname.phone' ),
Field::inst( 'lname.cellphone' ),
Field::inst( 'lname.identity' ),
Field::inst( 'pregroupdata.groupname' ),
Field::inst( 'pregroupdata.gdate' ),
Field::inst( 'pregroupdata.gtime' ),
Field::inst( 'pregroupdata.gplace' ),
Field::inst( 'pregroupdata.property' ),
Field::inst( 'zlname.name'),
Field::inst( 'zlname.phone'),
Field::inst( 'zlname.cellphone'),
Field::inst( 'zlname.identity' )
)
->leftJoin('leader as lname', 'pregroupdata.leaderid','=','lname.id')
->leftJoin('zonedata as zname', 'pregroupdata.zoneid','=','zname.id')
->leftJoin('pastoral as pname', 'pregroupdata.pastoralid','=','pname.id')
->leftJoin('leader as zlname', 'zlname.id','=','zname.leaderid')
->on('preGet', function($editor, $id){
$editor
->field('pregroupdata.status')
->setValue('test');
})
->process( $_POST )
->json();
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.