Add a attribute/comment to a column
Add a attribute/comment to a column
Wooly65
Posts: 85Questions: 25Answers: 1
Is there an easy way to add an extra attribute/comment to a column to be retrieved later. For each column we want to add metadata to be used later when processing the table. I currently define on dataTable using:
looping ({
cols.push(
{
title : label,
data : field,
comment : 'something interesting'
}
);
});
jqDataTable.DataTable({
...,
columns : cols,
deferRender : true
});
Then later we could perform:
$('#jqDataTable').dataTable().api().columns().comment()
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi @Wooly65 ,
There's two things you could do - there's
columns.name
andcolumns.className
, both of those would give you some form of metadata.Cheers,
Colin
Thanks for the response @colin . I had previously thought about both.
columns.className
- I didn't want to misuse this attribute and cause potential HTML issues.columns.name
- I gave serious consideration to using this attribute since I don't need to reference a column by its name. But I can only use the attribute and not retrieve the attribute.table.column( 'location:name' ).data()
vstable.columns().name()
Hi,
Currently no - there isn't I'm afraid. It is something I've thought a lot about as it could be really useful for plug-ins and the like, but I've not settled on a way that I like yet.
Until then, the workaround is to use
column().header()
and then use$().data()
on the header cell. That way you can use jQuery to store the data just like you would any other column.Allan
Thank you for the suggestion. I was able to get that to work. Looks like you already use data to store the columnIndex.