Reputation: 176
I am trying to programmatically modify header text/color/style using a custom formatter. I looked at the question Tabulator - Having Column Header Resize when Font Size Changes which was nearly perfect, but the example formatter given looks like a cell formatter not a header title formatter.
A cell formatter takes three parameters whereas a header title formatter takes none. (I believe - and the docs seem to agree: http://tabulator.info/docs/4.2/format#format-column)
My question is simply "Is there any way for a header title formatter to determine which column it is in?"
If I'm wrong about the parameters, then that should help, but I use the exact format as given in the other answer but modify the code to
var customFormatter = function(cell, formatterParams, onRendered){
alert(cell == undefined)
}
and the browser returns 'true'. So it is being run as I get the alert, but no parameters. Which agrees with the docs.
My alternative, as I'm creating the many tabulators programmatically in php, is to create a different function for every column in every table. But that seems like a terrible solution.
Upvotes: 1
Views: 2926
Reputation: 176
I don't think I'm going to get a definitive answer from someone who knows this better than I do, but I'll stick with my initial position that the answer in the linked question was misleading.
A cell formatter has parameters:
var customFormatter = function(cell, formatterParams, onRendered){
alert(cell == undefined) // false
}
...whereas a titleformatter does not:
var customFormatter = function(){
// can really only do very generic stuff without parameters, only the return value matters
}
So the answer to my question is "No - you can't tell which column you're in when using a titleFormatter function", so you need one per column.
As I couldn't tell which column the formatter was for without creating a set of functions, I went a different way and instead created a fake but unique field name for each column and then once the table was set, ran through the header elements and mapped to them using the text in the header, and then modified the text to its proper value, and then could do what I liked with the header formatting.
If you're going a similar way, I only modified the text and background colours. Keep in mind the Tabulator doesn't know you've done this and might revert them, and my changes involved no resizing problems.
It meant I created an entire wrapper class for the Tabulator, but that has made it a lot more powerful anyway. Having said that, and having been through I think every free grid option out there, Tabulator is already strong enough as it is, in my opinion.
Upvotes: 0