Star header filter defaults to 5 stars instead of matching formatterParams
Star header filter defaults to 5 stars instead of matching formatterParams
##JSFIDDLE
https://jsfiddle.net/75qamdzg/1/
Description
Then a column uses the star formatter with more than five stars, adding a star header filter displays only five stars.
The star editor normally detects the number of stars used by the formatter when it is used on the same column. However, this detection does not work when the editor is used as a header filter.
Tabulator version
6.5.3
Minimal reproduction
new Tabulator("#example-table", {
data: [
{ id: 1, rating: 2 },
{ id: 2, rating: 7 },
{ id: 3, rating: 10 },
],
columns: [
{
title: "Rating",
field: "rating",
formatter: "star",
formatterParams: {
stars: 10,
},
headerFilter: "star",
},
],
});Actual behavior
The cells display ten stars, but the header filter displays only five stars.
Expected behavior
The header filter should display the same number of stars as the column formatter—ten in this example.
At a minimum, it would be helpful if the star header filter inherited the stars value from formatterParams when no explicit headerFilterParams.stars value is provided.
Workaround
Duplicating the setting appears to be necessary:
{
title: "Rating",
field: "rating",
formatter: "star",
formatterParams: {
stars: 10,
},
headerFilter: "star",
headerFilterParams: {
stars: 10,
},
}Possible cause
The star editor calculates the maximum number of stars using:
maxStars =
element.getElementsByTagName("svg").length ||
5;For a normal cell editor, the element may already contain the SVG stars generated by the formatter.
For a header filter, the filter element does not contain the formatter SVGs. Since formatterParams.stars is not inherited by headerFilterParams, the editor falls back to five stars.
Workaround :
maxStars =
(editorParams && editorParams.stars) ||
element.getElementsByTagName("svg").length ||
5;Documentation inconsistency
The editing documentation says that the star editor can automatically detect the number of stars when used on a column with the star formatter.
However, the header-filter documentation currently states that star editors are not available as header filters.
Despite that note, headerFilter: "star" is instantiated and is partly functional. It may therefore be preferable to either:
- officially support it and inherit the formatter star count;
- require
headerFilterParams.starsand document this explicitly; or - reject the unsupported header filter with a clear warning instead of silently rendering five stars.
Relevant documentation
Source: tabulator-tables/tabulator