How to select a column by clicking on a fixed header ?

How to select a column by clicking on a fixed header ?

puleddupuleddu Posts: 3Questions: 2Answers: 0

Hi Everyone,

What I'm trying to achieve is a column selection by either clicking on a fixed header <th />.
In fact, everything works when I use a simple table header, since it belongs to the actual datatables-enhanced table.

When using a fixed header, the click on the header is not listened (I guess because of the header duplication needed for the fixed header feature).

Example: http://live.datatables.net/rediqabe/1/edit

Could you perhaps give me a suggestion on how to handle this properly?

Answers

  • puleddupuleddu Posts: 3Questions: 2Answers: 0

    I managed to get the click by using the .dataTables_scrollHead and using the data.
    My mistake was trying to bind the click on the original table header, which is underneath the copy (given the FixedHeader feature).

    I hope this is the correct way to do that.

    $('.dataTables_scrollHead').on('click', 'td', function () {
        var index = $(this).data('column-index');
        console.log(index);
    });
    
This discussion has been closed.