the line doesn't appear after creation

the line doesn't appear after creation

SWATswatSWATswat Posts: 109Questions: 0Answers: 0
edited July 2020 in Editor

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

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    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

  • SWATswatSWATswat Posts: 109Questions: 0Answers: 0

    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.

     7  Object { query: "SELECT `r_i_d_a`.`id` as 'r_i_d_a.id', `r_i_d_a`.`perimetre` as 'r_i_d_a.perimetre',
        `perimetre_rida`.`nom_perimetre` as 'perimetre_rida.nom_perimetre', `r_i_d_a`.`clients` as 'r_i_d_a.clients',
        `client_rida`.`nom_client` as 'client_rida.nom_client', `r_i_d_a`.`activite` as 'r_i_d_a.activite',
        `activite_rida`.`nom_activite` as 'activite_rida.nom_activite', `r_i_d_a`.`date_decision` as 'r_i_d_a.date_decision',
        `r_i_d_a`.`i_d_a` as 'r_i_d_a.i_d_a', `r_i_d_a`.`problemes` as 'r_i_d_a.problemes', `r_i_d_a`.`cr…d_users_rida` = `r_i_d_a`.`users` 
        LEFT JOIN `status` ON `status`.`id_status` = `r_i_d_a`.`status` 
        LEFT JOIN `perimetre_rida` ON `perimetre_rida`.`id_perimetre` = `r_i_d_a`.`perimetre` 
        LEFT JOIN `client_rida` ON `client_rida`.`id_client` = `r_i_d_a`.`clients` 
        LEFT JOIN `activite_rida` ON `activite_rida`.`id_activite` = `r_i_d_a`.`activite` 
        LEFT JOIN `images` ON `images`.`id_images` = `r_i_d_a`.`etat` 
        WHERE `r_i_d_a`.`status` >= :where_0 AND `r_i_d_a`.`status` <= :where_1 AND `r_i_d_a`.`id` = :where_2 ", bindings: […] }
        query   "SELECT `r_i_d_a`.`id` as 'r_i_d_a.id', `r_i_d_a`.`perimetre` as 'r_i_d_a.perimetre',
        `perimetre_rida`.`nom_perimetre` as 'perimetre_rida.nom_perimetre', `r_i_d_a`.`clients` as 'r_i_d_a.clients',
        `client_rida`.`nom_client` as 'client_rida.nom_client', `r_i_d_a`.`activite` as 'r_i_d_a.activite',
        `activite_rida`.`nom_activite` as 'activite_rida.nom_activite', `r_i_d_a`.`date_decision` as 'r_i_d_a.date_decision',
        `r_i_d_a`.`i_d_a` as 'r_i_d_a.i_d_a', `r_i_d_a`.`problemes` as 'r_i_d_a.problemes', `r_i_d_a`.`cr…d_users_rida` = `r_i_d_a`.`users` 
        LEFT JOIN `status` ON `status`.`id_status` = `r_i_d_a`.`status` 
        LEFT JOIN `perimetre_rida` ON `perimetre_rida`.`id_perimetre` = `r_i_d_a`.`perimetre` 
        LEFT JOIN `client_rida` ON `client_rida`.`id_client` = `r_i_d_a`.`clients` 
        LEFT JOIN `activite_rida` ON `activite_rida`.`id_activite` = `r_i_d_a`.`activite` 
        LEFT JOIN `images` ON `images`.`id_images` = `r_i_d_a`.`etat` 
        WHERE `r_i_d_a`.`status` >= :where_0 AND `r_i_d_a`.`status` <= :where_1 AND `r_i_d_a`.`id` = :where_2 "
        bindings    [ {…}, {…}, {…} ]
        0   
        1   
        2   Object { name: ":where_2", value: "", type: null }
    

    An idea ?

  • SWATswatSWATswat Posts: 109Questions: 0Answers: 0

    I have a feeling it's the lastID recovery isn't working.

  • SWATswatSWATswat Posts: 109Questions: 0Answers: 0

    Allan,

    An idea, because I don't see why Datatables isn't retrieving the LastID please.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Is the id column a primary key and auto incrementing? What database are you connecting to here (Postgres, MySQL, etc)?

    Allan

  • SWATswatSWATswat Posts: 109Questions: 0Answers: 0
    edited July 2020

    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.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I wonder if it is to do with this:

    Field::inst( 'r_i_d_a.id' ),
    

    could you try:

    Field::inst( 'r_i_d_a.id' )->set(false),
    

    since you don’t want your user to be able to set the value of an auto incrementing field.

    Allan

  • SWATswatSWATswat Posts: 109Questions: 0Answers: 0

    Hi Allan,

    It's working perfectly well now.

    Many thanks.

This discussion has been closed.