Reputation: 1553
I have an ajax Tabulator in which I'd like to use a custom cell formatter on columns which are dynamically (but similarly) defined.
Let's say I have a dataset of People with "Event" columns, where the ajax response can contain up to 50 Event fields, named Event1,Event2...Event50. I could manually repeat the definitions using the Column Definition Array or Field Name Lookup Object approaches, like:
autoColumnsDefinitions:{
PersonID: { title:"ID #", align:"right"},
Event1: {formatter: eventFormatter},
Event2: {formatter: eventFormatter},
...[variable # of Event cols here]...
},
...
function eventFormatter(cell){
// format event here
}
However, using a callback seems more appropriate. When I try something like this, my eventFormatter is never invoked, and no errors or warnings are raised.
autoColumnsDefinitions:function(definitions){
definitions.forEach((column) => {
if(column.field.match(/Event/)) {
column = {
formatter:eventFormatter
}
}
Is it possible to apply a custom cell formatter to fields that are not explicitly named prior to data loading?
Upvotes: 0
Views: 568