Get Column ID by Name inside of rowCallback
Get Column ID by Name inside of rowCallback
dpanscik
Posts: 202Questions: 47Answers: 0
Is there a way to get the column ID number by name inside of rowCallback?
I have columns that move around, so on rowCallback i need a way to learn where they moved to.
This question has an accepted answers - jump to answer
Answers
The best option is to use objects for the rows along with
columns.data
. See the Data docs for details. The object name will stay the same when the column is moved.Kevin
Hi Kevin,
I don't see an obvious solution to use
columns.data
inside of rowCallback.Here is what I have tried in rowCallback
Guessing you are using
columns.name
. The formatInvoiceAmount:name
is used as acolumn-selector
with thecolumn()
API. You could usecolumns.className
to assign a class and use it as the.eq()
selector.It depends on what you are trying to do. Your question was a bit vague Lets say you have these columns:
You could do something like this:
Kevin
Im still not getting to a solution here.
I cant figure out the syntax to target a specific column. Here is my attempt to figure out the formatting to target a column by "data".
$('td', row).row.name('InvoiceAmount').css('background-color', '#8B8000');
Here is what I am trying to do.
Use
columns.className
then use that as part of the jQuery selector, like this$('td.InvoiceAmount', row)
. For example:https://live.datatables.net/dodobuge/2/edit
Kevin
Thank you Kevin! I appreciate your help.
Here is my final solution
$('td.InvoiceAmount', row).css('background-color', '#8B8000')