Permit dbclick on row

Permit dbclick on row

AnGe7AnGe7 Posts: 5Questions: 2Answers: 0
edited July 2017 in Free community support

Hello all,

I have this code :

$(".list-data-table-search").each(function(){
            var columns = [];

            var size = $(this).find('th').length;

            for(var i = 0; i <= size - 1;i++)
                columns.push(null);

            $(this).DataTable({
                "stateSave":true,
                "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "tout"]],
                "pageLength": 10,
                "language": {
                    "url": "/js/dataTableLang.json"
                },
                "ajax": {
                    url: $(this).data('url'),
                    pages: 50
                },
                "deferRender": true,
                "columns": columns
            });
        });

It permit to have dataTable to each object with "list-data-table-search" class, dynamically.

In PHP response i build my table like this :

$data = array();
$line = [ $col1, $col2, ... ];
$data[] = $line;

Ok, now i would like when i dbclick on TR i'm redirect to one page (data-attribute of TR) if key $line['url-to-redirect'] exists

I don't know how to do this,

someone can help me ?

Thank you

This question has an accepted answers - jump to answer

Answers

  • AnGe7AnGe7 Posts: 5Questions: 2Answers: 0

    nobody can help me ?

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin

    Perhaps this example will be useful. Rather than listening for click events though, listen for dblclick.

    Allan

  • AnGe7AnGe7 Posts: 5Questions: 2Answers: 0

    yeah Allan, that's exactly what i need but how to store my target's url in data[0] (for example) but not display it in table ?

    thx !

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin
    Answer ✓

    One option would be to use a hidden column - columns.visible.

    Another would be to have the URL as a data-* attribute for the row node, which you can then get with row().node().

    Allan

  • AnGe7AnGe7 Posts: 5Questions: 2Answers: 0
    edited August 2017

    nice, i setted data-visible on last <tr> and fix columns configuration like this : (for those who interest)

               var listTh = $(this).find('th');
                var size = listTh.length;
                for(var i = 0; i <= size - 1;i++) {
                    var th = listTh[i];
                    if($(th).attr('data-visible') == '0') {
                        columns.push({visible:false});
                    } else {
                        columns.push(null);
                    }
                }
    

    and after :

    $(this).on('dblclick', 'tr', function () {
                    var data = table.row( this ).data();
                    var len  = data.length - 1;
                    window.open(data[len], '_blank');
                });
    

    Thank you Allan

This discussion has been closed.