Update row from another page

Update row from another page

LapointeLapointe Posts: 373Questions: 70Answers: 4

Hi all

In page_1 I select a datatable row, then click a button that open page_2 that display a document and allow user to click on "export to pdf".
If user do export, I need to set a export date (il not already set) so I set (if exported to pdf) this value in sql table (using direct sql).
Page 2 may stay open or close, but

When I go to page_1, the selected row is not refreshed and the new value is set in the database (I can see it) but not displayed in datatable (not reloaded).

Is there a way to refresh table in page_1 calling something in page_2 ?

I know, christmas is december 24 this year...

Thanks

Replies

  • kthorngrenkthorngren Posts: 13,584Questions: 25Answers: 3,197

    ajax.reload() is the way to refresh a Datatable from the database, assuming you are using the ajax option.

    Are page_1 and page_2 two different pages of the same Datatable or two different web pages? If you want to copy something from page_2 to the selected row in page_1 then use row().data() to update the selected row. How this is done is specific to what you have.

    Kevin

  • colincolin Posts: 12,453Questions: 0Answers: 2,110
    edited January 31

    Without using websockets or something like that to communicate between the pages, you could use the focus event, perhaps, and reload the table with ajax.reload() - something like this,

    Colin

  • LapointeLapointe Posts: 373Questions: 70Answers: 4

    Hi guys

    Colin solution works fine, and is less complex than other solution...
    In fact when opening page_2 some buttons are displayed and allow user to get it in pdf or send it by mail, opening page_2 URI with option window.open(document.documentURI +'&P')
    so transporting row().data() is a little bit complex

    Thanks a lot.

  • LapointeLapointe Posts: 373Questions: 70Answers: 4

    Hi @colin @kthorngren @allan

    Hope everybody is fine

    Perhaps this post is not in good section (feature request) but I get a problem using @Colin solution so I keep this post to answer...

    I place reload on window focus as :

     $(window).focus(function(e) {
        table.ajax.reload(null, false);
      });
    

    So when I am in table with a row A selected
    I click out the window
    I click on row B and select it
    I edit row B ... or not

    Selected row will change to Row A after a few moment (at reload success)

    I try

    var r = table.row({selected:true});
    table.ajax.reload(function(json){
        table.row(r).select().show().draw(false);
    });
    

    or

    table.ajax.reload();
    

    with no more success :'(

    I know focus event is fired before row is selected in my sample, and table reload need some time, but I'm afraid wrong row editing or else.

    Is there a way to search for ?

    Another point... Can you tell me where I can find information (or tell me please) how to post sample at http://live.datatables.net/ using data file ? I can see you do it, but not find how to... :/

    Bob

  • colincolin Posts: 12,453Questions: 0Answers: 2,110

    It would be worth taking a look at CloudTables as this keeps the data up to date across all browser windows with the table open. This uses websockets to do this, which would be the only tidy way of guaranteeing that consistency,

    Colin

  • kthorngrenkthorngren Posts: 13,584Questions: 25Answers: 3,197

    Another point... Can you tell me where I can find information (or tell me please) how to post sample at http://live.datatables.net/ using data file ?

    This technote describes how to use the live.datatables.net environment.

    Kevin

  • LapointeLapointe Posts: 373Questions: 70Answers: 4

    hi all
    Thanks.
    I'll have a complete look at technote next

    For CloudTable, I'm not sure I'll can transpose complete app and test it in 15 days...

    PS Is there any tutorail in french, because my poor english ? B)

  • colincolin Posts: 12,453Questions: 0Answers: 2,110

    No, sorry, all the docs are only in English I'm afraid, and yours definitely isn't poor! Good luck with the deadline,

    Colin

  • LapointeLapointe Posts: 373Questions: 70Answers: 4

    Thanks... Don't worry. I know I'm Italian living in France...

    Just for information... Is there a way in CloudTable to set a complex depend system as, for example...

        function RecUsrDependent(UsrId){
            // si on est en création il faut charger les paramètres requis (usrParam)
            if(editor.mode()=='create') {
                $.ajax ({
                    url: 'getdata.php',
                    method: 'GET',
                    dataType: 'JSON',
                    async: false,
                    data: {
                        U:UsrId,
                        W:['ID','MultiLignes','ExoTVA','Situations','FamillesPrestations','RemiseGlobale','Prefix','NumFac','LienURSSAF'],
                        Opt:'utilisateurs'
                    },
                    success: function ( UsrData ) {
                        if (UsrData){
                            usrParam = UsrData;
                        }
                    }
                });
            }; // enf if create
            ";
            // si on est en mode admin et en création on définit les valeurs par défaut de facturation
            if ($IsAdmin) { $RecUsrDependentFct.="
            // TODO : ne pas afficher exotva sinon il apparait lors de la mise urssaf ou banque sur mono ligne
            // admin only
            editor.show('recettes.ExoTVA', false);
    
            if(editor.mode()=='create') {   // admin only
                editor.field('recettes.Prefix').set( ((usrParam.Prefix!=null) ? usrParam.Prefix :  GetCurYear()))
                editor.field('recettes.NumFac').set( ((parseInt(usrParam.NumFac) > 0) ? parseInt(usrParam.NumFac) + 1 : 1));
            };
            ";
            }
            // affichage des champs
            $RecUsrDependentFct .= "
            // si on est en mode admin et en création on définit les valeurs par défaut de facturation
            // on vérifie si il y a une prestation au niveau facture... dans ce cas si on est en mode edit on laisse les contrôles affichés
            if ( (editor.mode()=='edit') &&
                    (usrParam.MultiLignes == 1) &&
                    (recParam.ID_Prestation)
                ) {
                usrParam.MultiLignes = 0;
            }
            if (usrParam.MultiLignes == 1){
                // ici on masque Famille et prestations et on annule les réacteurs
                ShowField('prestations.ID_Famille', false, true);
                ShowField('recettes.ID_Prestation', false, true);
    
                if (usrParam.RemiseGlobale == 1){
                    ShowField('recettes.Remise');
                    editor
                    .field('recettes.Remise').label('Remise globale (%)');
                }
                else {
                    ShowField('recettes.Remise', false);
                }
    
                // on devrait ici définir le paramétrage de seceditor du fait du mline
                // non car la fonction n'est appelée que suir le open de editor
                // donc en cas d'accès direct ca coince
    
            } // end multilignes true
            else {
                ShowField('recettes.ID_Prestation');
                ShowField('recettes.Remise');
                editor
                .field('recettes.Remise').label('Remise (%)');
    
                // gestion des familles de prestation
                if (usrParam.FamillesPrestations == 1){
                    $.ajax ({
                        url: 'getdata.php',
                        method: 'POST',
                        dataType: 'JSON',
                        data: {
                            U:UsrId,
                            EmptyAllowed:true,
                            NotNull:false,
                            Opt:'prestations_familles',
                            order:'ID_Utilisateur DESC, Libelle ASC'
                        },
                        success: function ( JSON ) {
                            ShowField('prestations.ID_Famille');
                            editor
                            .field('prestations.ID_Famille').update( JSON );
                        }
                    });
                    // dans ce cas on react sur changement de famille
                    editor.dependent( 'prestations.ID_Famille', function ( FamId ) {
                        $.ajax ({
                            url: 'getdata.php',
                            method: 'GET',
                            dataType: 'JSON',
                            data: {
                                U:UsrId,
                                F:FamId,    // ici val est la famille
                                EmptyAllowed:true,
                                NotNull:false,
                                Opt:'prestations',
                                order:'ID_Utilisateur DESC, Libelle ASC'
                            },
                            success: function ( JSON ) {
                                editor.field('recettes.ID_Prestation').update( JSON );
                            }
                        });
                        return true;
                    });
                } // end familles true
                else {
                    // on met à jour la liste des prestations pour le user
                    ShowField('prestations.ID_Famille', false, true);
                    $.ajax ({
                        url: 'getdata.php',
                        method: 'GET',
                        dataType: 'JSON',
                        data: {
                            U:UsrId,
                            EmptyAllowed:true,
                            NotNull:false,
                            Opt:'prestations',
                            order:'ID_Utilisateur DESC, Libelle ASC'
                        },
                        success: function ( JSON ) {
                            editor.field('recettes.ID_Prestation').update( JSON );
                        }
                    });
                } // end famille false
    
                // si on a les prestations il faut permettre la recup du montant prestation lors de la création
                if(editor.mode()=='create') {
                    editor.dependent( 'recettes.ID_Prestation', function ( PrestId ) {
                        $.ajax ({
                            url: 'getdata.php',
                            method: 'POST',
                            data: {
                                U:PrestId,
                                W:['Montant','Description'],    // dans la table prestations
                                Opt:'prestations'
                            },
                            success: function ( PrestData ) {
                                if (PrestData){
                                    PrestData = JSON.parse(PrestData);
                                    var Mt = (PrestData.Montant) ? parseFloat(PrestData.Montant).toFixed(2) :'0.00';
                                    if (! isNaN(Mt)){
                                        editor.field('recettes.Montant').set( Mt );
                                    };
                                    editor.field('recettes.Commentaires').set( PrestData.Description );
                                }
                            }
                        });
                    return true;
                    });
                } // end if create
                else {
                    editor.undependent( 'recettes.ID_Prestation' );
                }
    
            }; // end multiligne false
    
            // gestion des situations
            if (usrParam.Situations == 1) {
                $.ajax ({
                    url: 'getdata.php',
                    method: 'POST',
                    dataType: 'JSON',
                    data: {
                        U:UsrId,
                        EmptyAllowed:true,
                        NotNull:true,
                        Opt:'situations',
                        order:'ID_Utilisateur DESC, Libelle ASC'
                    },
                    success: function ( JSON ) {
                        ShowField('recettes.ID_Situation');
                        editor
                        .field('recettes.ID_Situation').update( JSON );
                    }
                });
            }
            else {
                ShowField('recettes.ID_Situation', false);
            }
            // gestion de la remise client
            if (editor.mode()=='create'){
                if (((usrParam.MultiLignes == 1) && (usrParam.RemiseGlobale == 1)) || (usrParam.MultiLignes != 1)) {
                    // on met à jour la liste des prestations pour le user
                    editor.dependent( 'recettes.ID_Client', function ( CliId ) {
                        $.ajax ({
                            url: 'getdata.php',
                            method: 'GET',
                            data: {
                                U:CliId,
                                W:['Remise'],   // dans la table prestations
                                Opt:'clients'
                            },
                            success: function ( CliData ) {
                                if (CliData){
                                    CliData = JSON.parse(CliData);
                                    var Rem = (CliData.Remise) ? parseFloat(CliData.Remise).toFixed(2) :'0.00';
                                    if (! isNaN(Rem)){
                                        editor.field('recettes.Remise').set( Rem );
                                    };
                                }
                            }
                        });
                        return true;
                    });
                }
            } else {
                editor.undependent( 'recettes.ID_Client' );
            }
    
            // pas de sous action
            // gestion de la liste des patients de l'utilisateur (UsrId)
            $.ajax ({
                url: 'getdata.php',
                method: 'POST',
                dataType: 'JSON',
                data: {
                    U:UsrId,
                    labelField:'concat(`Nom`,\' \',`Prenom`)',
                    EmptyAllowed:true,
                    NotNull:true,
                    Opt:'clients'
                },
                success: function ( JSON ) {
                    editor.field('recettes.ID_Client').update( JSON );
                }
            });
    
            // pas de sous action
            // modes de règlement
            $.ajax ({
                url: 'getdata.php',
                method: 'POST',
                dataType: 'JSON',
                data: {
                    U:UsrId,
                    Opt:'modes_reglement',
                    order:'ID_Utilisateur DESC, Libelle ASC'
                },
                success: function ( JSON ) {
                    editor.field('recettes.ID_ModeReglement').update( JSON );
                }
            });
            return true;
        };
    
  • colincolin Posts: 12,453Questions: 0Answers: 2,110

    I'll say "yes", as the code can be as complex as you want! I'm not sure what you're trying to do, so harder to give a more accurate answer :)

    Colin

  • LapointeLapointe Posts: 373Questions: 70Answers: 4

    Hi @colin

    What I expect to do is a functional software with easy user experience.
    My users are all admin, and their users are final users...
    For final users, interface should be simple, but multiple user can access to the same software with many different settings (with or without (you or U2) :) options) AND admin (my client) must access all users datas and when editing user datas, interface must be the user interface, not the admin one.

    So I use PHP to create html / js / ... pages.
    I'm not sure I'll can store this project in CloudTable. I do have a look at the training videos (in english B) )... Nice system, but actually I have no needed time to learn another new system (I discover datatable less than 2 years) and to test new application.
    When this one (V 1.92 today) will be final release, I'll try CloudTable.
    If you want I did create an account for Alan to have a look at test database, but there is also a lot of functions I have to implement next year (next life ?))

    All case Thanks.

  • allanallan Posts: 54,542Questions: 1Answers: 8,528 Site admin
    edited February 3

    Realistically no, such a level of customisation isn't yet possible in CloudTables. It probably could be done, but it would be more work than getting Editor setup for your specific use case at the moment (CloudTables continues to evolve though, so in future....).

    Are you using window.open to open the second window? If so, you can use window.parent you call functions on the host page from the child page (the function just needs to be globally available on the parent). That function could then trigger a reload of the DataTable using ajax.reload().

    Allan

  • LapointeLapointe Posts: 373Questions: 70Answers: 4

    Hi @allan @all

    In past I did try use windev, and associated, after clipper and...

    I know CloudTable is the good way to create and manage applications, but it is not easy to allow in this HMI all possibility the level 0 language (C or ASM) can permit...
    Nobody can say this is not.

    For end user with some basic coding knowing, it will be possible to design a software themselve.

    Your products are really very nice, good (apologies but I don't know term to say awesome in english) in concept an realesation, and all your team seem to be geek of this environment.

    Thank you (all the team obviously) for all of those (non exclusive) points

    Regards
    Bob

  • LapointeLapointe Posts: 373Questions: 70Answers: 4

    PS you mean window.opener (because in my case (php) window.parent refer to window.self ?

  • allanallan Posts: 54,542Questions: 1Answers: 8,528 Site admin

    Many thanks for your kind works about CloudTables and our development in general :).

    These are the two Javascript functions I was referring to in my last message:

    I don't know how you'd do inter-window communication through PHP without a web-socket or Ajax long polling. I'm not sure it would be possible! The two Javascript functions above are how I've done inter-window communication before myself.

    Have a look at this Chrome experiment to see some amazing multi-window communication.

    Allan

  • LapointeLapointe Posts: 373Questions: 70Answers: 4

    Hi @allan
    I do it using js but window.opener nor window.parent....

    Working fine

    Thanks

  • allanallan Posts: 54,542Questions: 1Answers: 8,528 Site admin
  • LapointeLapointe Posts: 373Questions: 70Answers: 4

    Hi @allan
    Have a look at this Chrome experiment to see some amazing multi-window communication. is very nice.
    I remember in 1983 I did create a windows (text) system for dbase compiler (clipper Nantucket) and tools as ClockOn() and ClockOff() to get onscreen time display and ... I did use C and or interrups using asm (into clipper code) to do it.
    For Autodesk products (AAD in ADN) I did use Lisp... and import German softwares like 3D-Pipe and...
    BUT
    It was stone age....
    Today I just try to understand new worlds that comes as mushroom... each day my knowledge is less than yesterday.
    Thanks
    Bob

Sign In or Register to comment.