Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get clicked row data Jquery data table

I have jquery datatable and its grouped according to date. I want to add new event action when click group header. But I cannot get clicked group data. How to get clicked group data. I used below code, still cannot get clicked group data.

 $(document).ready(function(){
        var otable;
        otable = $('#data').DataTable({
            "bProcessing":true,
            "bServerside":true,
            "sServerMethod":"post",
            "sAjaxSource": "http://localhost/test/test",
            "bDestroy":true,
            "aaSorting":[[2,'desc']]
        }).rowGrouping({
            bExpandableGrouping:true,
            iGroupingColumnInex:6
        });



    $('#data body').bind('click','tr.group',function(){
       var data = $('#data').DataTable().row(this).data()
    });
 })
like image 818
Janzz dl Avatar asked Sep 20 '25 15:09

Janzz dl


1 Answers

Pass the tr element to an instance of the DataTables api. I changed your bind to on because it's the recommended way, change it back if you're using an older version.

$('#data body').on('click','tr.group',function(){
    var data = $(your table selector).DataTable().row(this).data();
});

EDIT: cleaner solution by commenter, thx

like image 185
Eric Guan Avatar answered Sep 22 '25 18:09

Eric Guan