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()
    });
 })

Answers 1

  • 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


Related Articles