Send click event

Send click event

NewcomaNewcoma Posts: 24Questions: 0Answers: 0
edited July 2013 in General
Hello
Im loading the dataTable script when I click a sortable column like this

$('.tables th').click(function(){

$('.tables').dataTable();

});

The problem is I want to both excecute the dataTable script and pass the click event to the .tables th to sort the column. But I have to click one more time on the column to do this.

Hope it makes sense.

Replies

  • NewcomaNewcoma Posts: 24Questions: 0Answers: 0
    Actually I activate it with this so it only initialize the dataTables once. But the problem is still the same

    $('.tables th').one("click", function() {
    $('.tables').dataTable();
    });
  • koosvdkolkkoosvdkolk Posts: 169Questions: 0Answers: 0
    What if you manually fire the fnSort function? Something like

    [code]
    $(document).ready(function() {
    $('.tables th').one("click", function() {
    var table = $('.tables').dataTable();
    table.fnSort( [ [0,'asc'], [1,'asc'] ] );
    });
    [/code]
  • NewcomaNewcoma Posts: 24Questions: 0Answers: 0
    Dose not work I only get table.fnSort is not a function
  • NewcomaNewcoma Posts: 24Questions: 0Answers: 0
    What I want to achieve is that when you click on $('.tables th') the dataTable is loaded for that table only like var oTable = $(this).closest('.tables').dataTable() and then the click for that th is passed at the same time to sort the column.

    Im not sure if this example pvovides a solution http://datatables.net/release-datatables/examples/advanced_init/dt_events.html
This discussion has been closed.