How do I get the name of a column from within a .on('click', '.region-column, .displayName-column',
How do I get the name of a column from within a .on('click', '.region-column, .displayName-column',
I've been trying to figure this out for .. longer than I care to admit. It seems like this would be a pretty simple thing, but I'm sure having a hard time. I've got an .on('click' ...) handler that fires if either one of two different columns is clicked in. (I'm trying to do editing using contentEditable, on a div within these two columns and don't want to make two separate handlers because DRY.)
$('#grid-data tbody').on('click', '.region-column, .displayName-column', function (oEvent) {
// experiments ...
var $this = $(this);
var $thisCell = customerRegionMappingDataTable.cell($this.parents('td'));
// I need the name of the field getting updated! Is it in $thisCell ?
// not that I can find.
// this works, but still don't know how to use it.
var cellIdx = this.cellIndex;
// didn't work
//var idx = this.cellIndex;
//var altCellIdx = customerRegionMappingDataTable.cell(this).index().column;
//var title = customerRegionMappingDataTable.column(idx).header();
//console.log('Column title clicked on: ' + $(title).html());
// neither of these appear to work either
var columnInfo = customerRegionMappingDataTable.columns(cellIdx);
var aRowInfo = customerRegionMappingDataTable.row($(this));
I need to know which column was clicked on/in so that when I update the value, I can persist the change back to the appropriate db field [via a $.ajax()
call or whatever].
Thanks!
Answers
Try
column().header()
. The example shown should give you the column name.Kevin
Hey Kevin,
Darn, I wasn't clear, sorry about that.
column().header()
does in fact give me the header text, e.g. "Column title clicked on: Displayed Customer Name", but I need the actual'name'
of the column. In this case, "displayName".Here's my column definition;
EDIT: Actually, now that I think about it, I should probably grab that 'data' value as well.
Thanks,
Scott
Anyone?
Bueler?
Bueler?
https://datatables.net/reference/api/column().name()
That method isn't actually available in DataTables 1.x. It is in my v2 branch (which is very very early stages) and I accidentally published the reference to the site. That method doesn't exist in the list of API methods, which is for the shipping version of DataTables.
Currently in 1.x there is no API method to get the
columns.name
property of a column I'm afraid.Allan