I'm using Tabulator JS and have 2 columns containing numeric data. First, I used the built-in money
formatter with formatterParams
parameters, and for the second one I wanted to apply exactly the same, with the same parameters, but also add, For example, the color of the cell. How to apply formatterParams
in a custom format?
new Tabulator("#data-table", { data: data, layout: "fitColumns", columns: [{ title: "Length", field: "length", formatter: zeroValueFormatter, formatterParams: { thousand: " ", precision: false } }, { title: "New length", field: "newLength", formatter: "money", formatterParams: { thousand: " ", precision: false } ], }); function zeroValueFormatter(cell, formatterParams /* ? */) { if (cell.getValue() === 0) { cell.getElement().style.backgroundColor = "#add8e6"; } return cell.getValue(); }
One option is to use
rowFormatter
and apply the formatting to the specific columns you need. In your example, it'slength
columns. This way you can use the built-inmoney
formatter at the column setting level for both columns, but apply other formatting at the row level. Here is an example: