2016-07-14 12 views
0

Ich benutze die letzte Version von Jquery Datatables (1.10.12), aber ich bin nicht in der Lage zu bekommen, welche Zelle angeklickt wird. Nach dem Dokumentationsbeispiel erhalte ich immer ein "undefined". Vielleicht ist das Problem mit der Datentabelle Definition? Ich kann alle clciekd Zeileninfo (erste console.log) aber nicht die Zelle sehen!Kann die Zelle nicht von einem Datatable (jquery) geklickt werden

$('#table_id tbody').on('click', 'tr', function() { 
     console.log(table.row(this).data()); 
     console.log(table.cell(this).index()); 
     console.log(table.cell(this).data()); 
    }); 

Best wishes,

Ivan

https://datatables.net/reference/api/cell().data()

Antwort

0

Weil Sie tr an die Zelle() -Methode sind vorbei.

$('#table_id tbody').on('click', 'tr', function() { // its a click on tr 
     console.log(table.cell(this).data()); // this <- is tr , will not work! 
    }); 

tun, um diese

$('#table_id tbody').on('click', 'td', function() { // its a click on td 
     console.log(table.cell(this).data()); // this <- is td 
    });