Double click on subtable (Datatable Jquery)

0

I have two tables, stories and history assignment. by clicking on a button in the history table, I see the tasks of that story as a subtable. Pressing double click on a row of the history table executes a function (A), the problem is that when executing a double click on a row of the subtable, I also execute the function (A). I would like to be able to distinguish the double click of the history table from the double click of the history task table.

function historias() {
    var parametros = {
        "interruptor": interruptor,
        "prsp":prsp
    };
    tableHistorias = $('#tbl_Historias').DataTable({
            "ajax": {
                "data": parametros,
                "url": "php/PlnDir/his_n_colab.php",
                "type": "POST",
                "dataSrc": "",
            },

            "columns": [{
                    "defaultContent": "<button type='button' id=\"idTareaH\" title=\"Tareas de historia\" class='tareas  btn btn-primary btn-xs '><span class='glyphicon glyphicon-pencil'></span></button>  <button type='button' id=\"idTareaH\" title=\"Añadir tarea a historia\" class='tarToHis  btn btn-primary btn-xs '><span class='glyphicon glyphicon-plus'></span></button>",
                    "width": "6%"
                }, {
                    "data": "id"
                }, {
                    "data": "name"
                }]
        });

    //Despliega las tareas de la historia
    $('#tbl_Historias tbody').off('click', 'button.tareas');
    $('#tbl_Historias tbody').on('click', 'button.tareas', function () {

        var tr = $(this).closest('tr');
        var row = tableHistorias.row( tr );
        var open = row.child.isShown();
        var data_formHisId = tableHistorias.row($(this).parents("tr")).data();
        tableHistorias.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
            if (this.child.isShown()) {
                this.child.hide();
                $(this.node()).removeClass('shown');
            }
        });

        if(!open){
                tareaDhistoria(data_formHisId['id'], function (tablaTarea) {
                row.child(tablaTarea).show(); //Esta escondido, llamo a la función
                tr.addClass('shown');   
            });
        }
    });


    //Al hacer doble click, entro la historia
    $('#tbl_Historias tbody').off('dblclick', 'tr'); 
    $('#tbl_Historias tbody').on('dblclick', 'tr', function () {
        var idH = tableHistorias.row( this ).data();
        origen = "html/PlnDir/historias.html";
        PlnDir('php/PlnDir/formHistoria.php?idHis=' + idH['id'] + '&origen=' + origen, "PlnDir", "historia");
    });

}

Here the subtable.

function tareaDhistoria(id,callbackFunction) {
    var parametros = {
        "idHis": id,
    };

    $.ajax({
        data: parametros,
        "url": "php/PlnDir/his_tarea.php",
        type: "POST",
        success: function (data) {
            objJson = JSON.parse(data);
            var tablaTarea = '<div class="table-responsive">' + '<table id="tblTareaH" cellspacing="0" width="100%">' + '<thead>' + '<tr  HEIGHT="3">' + '<td  BGCOLOR="#D0D3D4">' + '<p>Tareas</p>' + '</td>' + '<td  BGCOLOR="#D0D3D4">Id:</td>' + '<td  BGCOLOR="#D0D3D4">Tarea</td>' + '<td  BGCOLOR="#D0D3D4">Descripción</td>' + '<td  BGCOLOR="#D0D3D4">Colaborador</td>' + '</tr>'
            + '</thead>' + '<tbody>';
            $.each(objJson, function (i, item) {
                tablaTarea += '<tr  style="cursor: pointer;">' + '<td>' + '<button type=\"button\"  title=\"Ir a tarea\" class=\"TareaH  btn btn-primary btn-xs \"><span class=\"glyphicon glyphicon-pencil\"></span></button>' +  '<td>' + objJson[i].id + '</td>' + '<td>' + objJson[i].name + '</td>'+'</th>'  + '<td>' + objJson[i].dsc + '</td>' + '<td>' + objJson[i].colab_name + '</td>' + '</tr>';
            });
            tablaTarea += '</tbody>' + '</table>' + '</div>';
            callbackFunction(tablaTarea);
            tblT = $('#tblTareaH').DataTable({
                "responsive": true,
                "destroy": true,
                "paging": true,
            });
        }
    });

Here, I would like to execute the code by double clicking, but if I do it, I double click on the story.

$('table').off('click', 'button.TareaH');
        $('table').on('click', 'button.TareaH', function () {
        var idT = tblT.row($(this).parents("tr")).data();
            PlnDir('php/PlnDir/formTarea.php?idMisTareas=' + idT[1] + "&historia=" + id, "PlnDir", "tarea");       
        });

    }
    
asked by Lorenzo Martín 25.08.2018 в 16:23
source

0 answers