Copy information in 2 tables

Copy information in 2 tables

SWATswatSWATswat Posts: 83Questions: 0Answers: 0

Is it possible to record identical data on 2 different tables while maintaining
visualization in the table of a single table with datatable editor.

example : datatable editor with database->table Car1

-------------
-   car 1   -
-------------
 -ID
 -couleur
 -marque
 -modele
 -nombre de place
 -nombre de porte
 -equipements
 -type
 -usage

and if validate a new entry in table Car1 with datatable editor, datatable create a copy in table Car2 :
Don't play the information of car2 in datatable editor (just copy information in other table)

-------------
-   car 2   -
-------------
 -ID
 -couleur
 -marque
 -modele
 -usage

It is possible ?

Thanks for your Help.

Replies

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @SWATswat ,

    I don't fully understand, but this example here may help. It shows how items can be transferred from one table to another.

    Cheers,

    Colin

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394

    You might want to try a postCreate event:
    https://editor.datatables.net/reference/event/postCreate

  • SWATswatSWATswat Posts: 83Questions: 0Answers: 0

    hello,
    I'd just like to copy some information from first table SGBD (view for datatable) into the seconde table SGBD (not seen by datatable) when creating a row in à first table SGBD.

    sorry for my bad english.

  • SWATswatSWATswat Posts: 83Questions: 0Answers: 0

    Hello,

    I want to duplicate some data of the line I just created in a second table with -> on (postCreat ...), but it does not work with the code below.
    I get this error:

    DataTables warning: table id = archive - Ajax error. For more information about this error, please see http://datatables.net/tn/7
    

    Certainly, I do not use this function properly.
    for information, if I remove the block -> on (postCreat ...), the script works perfectly.

    Can you help me please.

    Editor::inst( $db, 'archives_reception', 'id' )
        ->fields(
            Field::inst( 'date_prevu' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'heure_prevu' )->validator( Validate::dateFormat(
                    'H:i:s',
                    ValidateOptions::inst()
                        ->allowEmpty( false )
                ) ),
            Field::inst( 'transporteur_ok' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'immatriculation' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'nbre_palette' )->validator( 'Validate::numeric' ),
            Field::inst( 'cofor' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'heure_arrivee' )
                ->validator( Validate::dateFormat(
                    'H:i:s',
                    ValidateOptions::inst()
                        ->allowEmpty( false )
                ) ),
            Field::inst( 'heure_debut_dechargement' )->validator( 'Validate::required' )
              ->validator( Validate::dateFormat(
                    'H:i:s',
                    ValidateOptions::inst()
                        ->allowEmpty( false )
                ) ),
            Field::inst( 'heure_fin_dechargement' )->validator( 'Validate::required' )
              ->validator( Validate::dateFormat(
                    'H:i:s',
                    ValidateOptions::inst()
                        ->allowEmpty( false )
                ) ),
            Field::inst( 'heure_depart' )->validator( 'Validate::required' )
              ->validator( Validate::dateFormat(
                    'H:i:s',
                    ValidateOptions::inst()
                        ->allowEmpty( false )
                ) ),
            Field::inst( 'reservation_transporteur' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'poc_recu' )->validator( 'Validate::numeric' ),
            Field::inst( 'poc_attendu' )->validator( 'Validate::numeric' ),
            Field::inst( 'arrivalid' )->validator( 'Validate::notEmpty' )
        )
        /**/->on( 'postCreate', function ( $editor, $id, $values, $row ) {
            $editor->db()->insert( 'archives_liste_attente', array(
                'liste_nom_transporteur' => $row['transporteur_boat_ok'],
                'liste_heure_prevu' => $row['heure_prevu'],
                'liste_arrival_id' => $row['arrivalid'],
                'liste_cofor' => 'test',
                'liste_heure_arrivee' => $row['heure_arrivee'],
                'liste_type_arrivage' => 'HAUTO',
                'liste_urgence' => 'NON',
                'liste_traiter' => 'NON'
            );
        } )
        ->where('date_prevu', $MyDate_1)
        ->process( $_POST )
        ->json();
    
  • allanallan Posts: 61,656Questions: 1Answers: 10,094 Site admin

    Using a server-side postCreate event is how I would suggest you do it.

    Your reply above says you are getting invalid JSON in return from the server. What is being sent back? Is there an error message indicating what might be going wrong? If not there, then having a look in the server's error logs. I don't immediately see what would be wrong there, but the error message will hopefully clarify what is going on.

    The other option is to use a database trigger, which might be quite attractive if data can be inserted from somewhere other than Editor.

    Allan

  • SWATswatSWATswat Posts: 83Questions: 0Answers: 0

    Hello Allan,

    After correcting the line 52 with an addition of ")" and passage in ServerSide, it works very well.

    Is it possible to do the same process with postEdit and UPDATE and a WHERE condition see the code below? (this example is wrong it's just for the idea)

    ->on( 'postEdit', function ( $editor, $id, $values, $row ) {
    
            $editor->db()->update( 'archives_liste_attente', array(
                
                'liste_nom_transporteur' => $row['transporteur_ok'],
                'liste_heure_prevu' => $row['heure_prevu'],
                'liste_arrival_id' => $row['arrivalid'],
                'liste_cofor' => 'test',
                'liste_heure_arrivee' => $row['heure_arrivee'],
                'liste_type_arrivage' => 'HAUTO',
                'liste_urgence' => 'NON',
                'liste_traiter' => 'NON'
                    WHERE 'id_archives_reception' = $row['id']
            ));
        } )
    

    Thanks for in advance

  • SWATswatSWATswat Posts: 83Questions: 0Answers: 0

    Hello Allan,

    I reformulate, what is the good format for embedding a where clause in Postedit ?

    Thanks for your help.

  • allanallan Posts: 61,656Questions: 1Answers: 10,094 Site admin

    The third parameter for the ->update() method can be used as the where condition.

    Allan

This discussion has been closed.