Is your feature request related to a problem? Please describe.*
Sometimes when a cell is empty, I would like a placeholder text to be displayed instead of simply an empty cell.
Describe the solution you'd like
I'd like to be able to define a placeholder in my column definitions, like this:
columns: [
{
title: "Date of birth",
field: "dob",
formatter: "date",
placeholder: "Unknown"
}
]
In this example, if a valid date is set in the data, then it will be displayed and formatted per the date formatter and any formatter options given. But on rows where the value is empty/null/undefined, then it should instead switch to displaying the placeholder text.
This should also be given a class such as tabulator-cell-placeholder so that I can style the placeholders consistently I'd style them in italics and a greyed-out colour. Something similar would also be needed in the supplied themes.
Describe alternatives you've considered
I've implemented a solution for this in my own code which works. However it's quite clunky, as it requires basically taking every field where I want a placeholder and changing their formatters to adaptable, in order to override them with the placeholder formatter if the field value is empty. This is clunky and gets very ugly when I actually want an adaptable field.
It would be much neater if the feature was built into the core formatters module.
I've put the placeholder property as a top-level property in the cell definition. I guess it could also go into the formatterOptions if you feel that works better. But for me, I think it's better at the top-level, as it isn't part of the formatter, and would need to apply regardless of which formatter was in use (even custom ones).
I'm aware that placeholder is already a property of the table, in which case it is used for a string to display if no data is found. This cell-level placeholder is different, and does not clash with the existing placeholder. You may want to name it cellPlaceholder or something similar if you feel it's necessary to avoid confusion, but I think being in different parts of the table definition structure should be enough to differentiate them, even with the same property name.
There is also a separate thing of a field placeholder, which is a standard html feature for input fields to display when their value is empty. Note that this is not what I'm proposing here! My proposed feature is for cell formatting, not editing. You may want to consider implementing something for editing as well though, although I'd expect that it would need a separate placeholder string from this one.
Additional context
In my own code, I've also re-used my placeholder formatter for certain cases where data is invalid, to display an "Invalid value" string. This is obviously not the main use-case for the formatter, but it would be helpful to allow direct access to the placeholder formatter method so that I can still do this.
Is your feature request related to a problem? Please describe.*
Sometimes when a cell is empty, I would like a placeholder text to be displayed instead of simply an empty cell.
Describe the solution you'd like
I'd like to be able to define a placeholder in my column definitions, like this:
In this example, if a valid date is set in the data, then it will be displayed and formatted per the date formatter and any formatter options given. But on rows where the value is empty/null/undefined, then it should instead switch to displaying the placeholder text.
This should also be given a class such as
tabulator-cell-placeholderso that I can style the placeholders consistently I'd style them in italics and a greyed-out colour. Something similar would also be needed in the supplied themes.Describe alternatives you've considered
I've implemented a solution for this in my own code which works. However it's quite clunky, as it requires basically taking every field where I want a placeholder and changing their formatters to
adaptable, in order to override them with the placeholder formatter if the field value is empty. This is clunky and gets very ugly when I actually want an adaptable field.It would be much neater if the feature was built into the core formatters module.
I've put the
placeholderproperty as a top-level property in the cell definition. I guess it could also go into theformatterOptionsif you feel that works better. But for me, I think it's better at the top-level, as it isn't part of the formatter, and would need to apply regardless of which formatter was in use (even custom ones).I'm aware that
placeholderis already a property of the table, in which case it is used for a string to display if no data is found. This cell-level placeholder is different, and does not clash with the existing placeholder. You may want to name itcellPlaceholderor something similar if you feel it's necessary to avoid confusion, but I think being in different parts of the table definition structure should be enough to differentiate them, even with the same property name.There is also a separate thing of a field placeholder, which is a standard html feature for input fields to display when their value is empty. Note that this is not what I'm proposing here! My proposed feature is for cell formatting, not editing. You may want to consider implementing something for editing as well though, although I'd expect that it would need a separate placeholder string from this one.
Additional context
In my own code, I've also re-used my placeholder formatter for certain cases where data is invalid, to display an "Invalid value" string. This is obviously not the main use-case for the formatter, but it would be helpful to allow direct access to the placeholder formatter method so that I can still do this.