Select-Deselect

Select-Deselect

UMR5558UMR5558 Posts: 41Questions: 13Answers: 0

Hello everybody.
In my datatable when i select a row since a row is selected yet i detect 2 events:a deselected event + a selected event. I would like to do the deselect before the select. I want to be sure that all the functions are finished in my deselect event before doing functions in my select event.
Thanks for your help.
Lionel

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    The deselect does occur before the select, see here. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.

    Cheers,

    Colin

  • UMR5558UMR5558 Posts: 41Questions: 13Answers: 0

    Hello Colin, thanks for your help.
    I do the same thing in your example.
    The problem is in my two events i have many functions or jquery effects and i would like doing all in my function of deselect event before doing all in my function of select event. I try to explore the way of async functions with await but it's not working well.
    I try something like this

    table['data'].on('select', async function(e, dt, type, indexes) {
    console.log('select logged');
    // projet selectionne
    project_selected = true;
    var nb_utilisation = '';
    // initialisation des variables locales en fonction du choix du projet
    selected_line = indexes;
    project_name = table['data'].row(indexes).data().data.name;
    project_id_librairie = table['data'].row(indexes).data().data.id_librairie;
    author_name = table['data'].row(indexes).data().author.first_name +' '+table['data'].row(indexes).data().author.last_name;
    author_email = table['data'].row(indexes).data().author.email;
    project_status_id = table['data'].row(indexes).data().data.status_id;
    var keywords_method_projet = table['data'].row(indexes).data().keyword_method;
    var keywords_theme_projet = table['data'].row(indexes).data().keyword_theme;
    var nb_keywords_method = keywords_method_projet.length;
    var nb_keywords_theme = keywords_theme_projet.length;

    //fonctions
    console.log('reload_session'+reload_session);
    if (reload_session == false){
    await select_project('data', project_name, user_email)
    .done(function(answer) {
    nb_utilisation = answer.rows[0].nb_utilisation;
    })
    .fail(function (answer) {
    console.log(answer);
    });
    }

    console.log('project_status_id'+project_status_id);
    console.log('nb_utilisation'+nb_utilisation);
    // dans le cas du 2 publish on github necessite de faire de SF vers temp_project pour pouvoir lire les fichiers par R
    if (project_status_id == 2 && nb_utilisation == 1) {
    await transfert_files_SF_temp_project(token, project_id_librairie, project_type, project_name);
    }

    table['data'].on('deselect', async function(e, dt, type, indexes) {
    console.log('deselect');
    //projet deselectionne
    project_selected = false;
    reload_session = false;

    //RAZ variables
    project_id_librairie = '';
    project_name = '';
    project_status_id = '';
    author_name = '';
    author_email = '';
    selected_line = '';

    var nb_utilisation = '';

    // test pour detecter si on vient bien d'une ligne selectionnée
    if (indexes.length == 1){
    // initialisation des variables locales en fonction de la deselection du projet
    var project_name_deselect = table['data'].row(indexes).data().data.name;
    var project_status_id_deselect = table['data'].row(indexes).data().data.status_id;
    /// changement dans la bdd
    await deselect_project('data', project_name_deselect, statut_logging)
    .done(function(answer) {
    nb_utilisation = answer.rows[0].nb_utilisation;
    })
    .fail(function (answer) {
    console.log(answer);
    });
    $("#create_button").show();
    console.log('la')
    $("#edit_button").hide();
    //raz de l accordeon
    $('#accordion .collapse.show').toggleClass('show');
    $("span[id^=etape_]").removeClass("glyphicon-ok").addClass("glyphicon-unchecked");
    $(".glyphicon-arrow-down").addClass("glyphicon-arrow-up").removeClass("glyphicon-arrow-down");
    $(".glyphicon-arrow-right").addClass("glyphicon-arrow-up").removeClass("glyphicon-arrow-right");
    $("#project_name").html(texts_page_objects.accordion1_title);

    Many thanks for your answer.
    Lionel

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Yep, happy to look at it if you can update my example as requested,

    Colin

  • UMR5558UMR5558 Posts: 41Questions: 13Answers: 0

    Hi Colin. I'm very sorry for my bad english but i don't really understand what do you want from me and how i can do. I think i can add somme code in your example i will try.
    Little by little i manage to understand where my problem is. It's a synchronicity problem. In the deselect event I have 2 functions the second depend on the first result thats why i use an await function ans add async in my deselect function. So when i add await the select event function start before the end of deselect event function.
    The way i find is removing the await and move my second function in the done of the first.
    I will try to add my starting code in your example and maybe you will can to give me your opinion
    Thanks a lot for all

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    The problem is that for me it works, and to take this further we need to see your code failing. Without seeing the problem, which as you say is timing/async based, it's impossible to suggest a solution.

    Colin

This discussion has been closed.