the line doesn't appear after creation
the line doesn't appear after creation
Hello,
I have a new problem, the line doesn't appear after creation (appear after refresh navigator).
When I edit or delete a line there is no problem, everything is fine.
I don't know where the error is, I checked the Where condition and it works correctly.
Do you have an idea?
Datatables Editor PHP v1.9.0 inline
My code (Staff):
// DataTables PHP library
include( "Editor-PHP-1.9--pour_RIDA/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;
/*
* Example PHP implementation used for the join.html example
*/
Editor::inst( $db, 'r_i_d_a' )
->field(
Field::inst( 'r_i_d_a.id' ),
Field::inst( 'r_i_d_a.perimetre' )
->options( Options::inst()
->table( 'perimetre_rida' )
->value( 'id_perimetre' )
->label( 'nom_perimetre' )
)
->validator( Validate::dbValues() ),
Field::inst( 'perimetre_rida.nom_perimetre' ),
Field::inst( 'r_i_d_a.clients' )
->options( Options::inst()
->table( 'client_rida' )
->value( 'id_client' )
->label( 'nom_client' )
)
->validator( Validate::dbValues() ),
Field::inst( 'client_rida.nom_client' ),
Field::inst( 'r_i_d_a.activite' )
->options( Options::inst()
->table( 'activite_rida' )
->value( 'id_activite' )
->label( 'nom_activite' )
)
->validator( Validate::dbValues() ),
Field::inst( 'activite_rida.nom_activite' ),
Field::inst( 'r_i_d_a.date_decision' )
->validator( Validate::dateFormat( 'Y-m-d' ) )
->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ) )
->setFormatter( Format::dateFormatToSql('Y-m-d' ) )
->getFormatter( function ( $val, $data, $opts ) {
if ($val === "0000-00-00"){ echo ""; }else{ return date( 'Y-m-d', strtotime( $val ) ); }
} ),
Field::inst( 'r_i_d_a.i_d_a' ),
Field::inst( 'r_i_d_a.problemes' ),
Field::inst( 'r_i_d_a.criticite_rida' ),
Field::inst( 'r_i_d_a.solutions' ),
Field::inst( 'r_i_d_a.date_deadline' )
->validator( Validate::dateFormat( 'Y-m-d' ) )
->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ) )
->setFormatter( Format::dateFormatToSql('Y-m-d' ) )
->getFormatter( function ( $val, $data, $opts ) {
if ($val === "0000-00-00"){ echo ""; }else{ return date( 'Y-m-d', strtotime( $val ) ); }
} ),
Field::inst( 'r_i_d_a.etat_avancement' ),
Field::inst( 'r_i_d_a.status' )
->options( Options::inst()
->table( 'status' )
->value( 'id_status' )
->label( 'nom_status' )
)
->validator( Validate::dbValues() ),
Field::inst( 'status.nom_status' ),
Field::inst( 'r_i_d_a.etat' )
->options( Options::inst()
->table( 'images' )
->value( 'id_images' )
->label( 'nom_images' )
)
->validator( Validate::dbValues() ),
Field::inst( 'images.nom_images' ),
Field::inst( 'r_i_d_a.users' )
->options( Options::inst()
->table( 'users_rida' )
->value( 'id_users_rida' )
->label( 'trigramme_users_rida' )
)
->validator( Validate::dbValues() ),
Field::inst( 'users_rida.trigramme_users_rida' ),
Field::inst( 'r_i_d_a.commentaire' ),
Field::inst( 'r_i_d_a.date_realisation' )
->validator( Validate::dateFormat( 'Y-m-d' ) )
->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ) )
->setFormatter( Format::dateFormatToSql('Y-m-d' ) )
->getFormatter( function ( $val, $data, $opts ) {
if ($val === "0000-00-00" || $val === "" || $val === NULL){ echo ""; }else{ return date( 'Y-m-d', strtotime( $val ) ); }
} ),
Field::inst( 'r_i_d_a.date_verification' )
->validator( Validate::dateFormat( 'Y-m-d' ) )
->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ) )
->setFormatter( Format::dateFormatToSql('Y-m-d' ) )
->getFormatter( function ( $val, $data, $opts ) {
if ($val === "0000-00-00" || $val === "" || $val === NULL){ echo ""; }else{ return date( 'Y-m-d', strtotime( $val ) ); }
} ),
Field::inst( 'r_i_d_a.resultat' )
)
->leftJoin( 'users_rida', 'users_rida.id_users_rida', '=', 'r_i_d_a.users' )
->leftJoin( 'status', 'status.id_status', '=', 'r_i_d_a.status' )
->leftJoin( 'perimetre_rida', 'perimetre_rida.id_perimetre', '=', 'r_i_d_a.perimetre' )
->leftJoin( 'client_rida', 'client_rida.id_client', '=', 'r_i_d_a.clients' )
->leftJoin( 'activite_rida', 'activite_rida.id_activite', '=', 'r_i_d_a.activite' )
->leftJoin( 'images', 'images.id_images', '=', 'r_i_d_a.etat' )
->where('r_i_d_a.status', '1', '>=')
->where('r_i_d_a.status', '4', '<=')
->process($_POST)
->json();
Thank you in advance for your help
This discussion has been closed.
Replies
Can you show me the JSON response from the server in reply to the create Ajax request?
My guess is that
data
will be an empty array. If that is the case, then it means that the query being used to get the data is not matching anything in the database. You could add->debug(true)
just before the->process($_POST)
call to see the executed SQL and see why that might be the case.Allan
Thanks for your help.
I see that in object 7 Datatable makes a Select and it doesn't get the id of the line.
But I don't understand why it does and then it inserts the line in the database and it works for an update and a delete.
I'm a little bit lost here
Here is the answer of the browser.
An idea ?
I have a feeling it's the lastID recovery isn't working.
Allan,
An idea, because I don't see why Datatables isn't retrieving the LastID please.
Is the
id
column a primary key and auto incrementing? What database are you connecting to here (Postgres, MySQL, etc)?Allan
Hi Allan,
Yes, the ID column is auto incrementing and is a primary key.
Database is Mysql v10.3.22-MariaDB-0+deb10u1
I use other application with datatables EDITOR and I don't have this problem it's just with the inline version.
I wonder if it is to do with this:
could you try:
since you don’t want your user to be able to set the value of an auto incrementing field.
Allan
Hi Allan,
It's working perfectly well now.
Many thanks.