get the title of a column in a cell-event?

get the title of a column in a cell-event?

pballhausenpballhausen Posts: 2Questions: 0Answers: 0
edited November 2011 in General
Hello DataTables enthusiasts
I'm still a beginner in the use of DataTables and my English is not very good. I have a question, the answer is probably relatively simple:

I want to replicate the functionality of jEditable. So it is based on the class of a cell to open a dialog where you can enter either a text or selecting via radio or checkbox etc..

For this I have devised the following:

[code]
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
$(nRow).attr('id', aData[19]); //User id ist stored in cell 19
return nRow;
},
"fnDrawCallback": function() {
oTable = $('#userTable').dataTable();
$('td').hover( function() {
$(this).addClass('highlighted');

$(this).click( function() {
var cell_classes = this.className;
var cell_value = this.textContent;
var user_id = this.parentNode.id;
var col_index = this.cellIndex;
} );

}, function() {
$('td.highlighted').removeClass('highlighted');
} );
}
[/code]

Additionally, I have but not all columns are displayed. cell index is not equal aTargets of aoColumn.

So I need a way to get the title of a column in a cell-event ..

Replies

  • pballhausenpballhausen Posts: 2Questions: 0Answers: 0
    okay I just got a solution..

    [code]
    var col_title = $('td', this.parentNode).parents()[2].children[0].children[0].cells[col_index].textContent;
    console.dir(col_title);
    [/code]

    only problem is, when I redraw the Table, for example because of show another column, the "col_title" will be shown more than one time in the console..
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    I would say that the jQuery $().index() method is probably what you want here. That will give you the index of the element you are working with, relative to a given selector - thus making the code a lot more flexible. Then with the index you can use the 'eq' selector option to get just the column title you want. Alternatively a plug-in API method could be created to give you the column title based on the column index from the internal data store (aoColumns[].sTitle): datatables.net/blog/Creating_feature_plug-ins

    Allan
This discussion has been closed.