4

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

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

5 Comments

No need to pass jQuery object, row(this) will also work.
Post your html and js please. Have you initialize DataTables correctly?
How did you implement my answer, did you use otable or $('#data')?
It creates this error $('#data').DataTable().row is not a function
I can't see anything that would cause that error. If you make me a jsfiddle recreating the error then i can help more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.