You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 1, 2025. It is now read-only.
`Formatters` are functions that can be used to change and format certain column(s) in the grid. Please note that it does not alter the input data, it simply changes the styling by formatting the data differently to the screen (what the user visually see).
16
19
17
20
A good example of a `Formatter` could be a column name `isActive` which is a `boolean` field with input data as `True` or `False`. User would prefer to simply see a checkbox as a visual indication representing the `True` flag, for this behavior you can use `Formatters.checkmark` which will use [Font-Awesome](http://fontawesome.io/icons/) icon of `fa-check` when `True` or an empty string when `False`.
18
21
19
-
For a [UI sample](Formatters.md#ui-sample), scroll down below.
22
+
For a [UI sample](#ui-sample), scroll down below.
20
23
21
24
#### Provided Formatters
22
25
@@ -127,7 +130,7 @@ SlickGrid only has 1 `formatter` property but if you want to use more than 1 For
127
130
**Note:** please note that combining multiple Formatters has the side effect of cascading the formatted `value` output to the next Formatter. So for example if you use the `complexObject` and `dollar` Formatters, you want to make sure to define them in the correct order in your `formatters: []` array as shown below.
128
131
129
132
* what if you want to avoid overwriting the `value` with a Custom Formatter?
130
-
* in that case you can have your Formatter return a [FormatterResultObject](Formatters.md#formatterresultobject), see below.
133
+
* in that case you can have your Formatter return a [FormatterResultObject](#formatterresultobject), see below.
#### Example of a Custom Formatter with string output
174
+
#### Example of a Custom Formatter with HTML string
172
175
173
-
For example, we will use `Font-Awesome` with a `boolean` as input data, and display a (fire) icon when `True` or a (snowflake) when `False`. This custom formatter is actually display in the [UI sample](Formatters.md#ui-sample) shown below.
176
+
For example, we will use `Font-Awesome` with a `boolean` as input data, and display a (fire) icon when `True` or a (snowflake) when `False`. This custom formatter is actually display in the [UI sample](#ui-sample) shown below.
174
177
175
178
```ts
176
179
// create a custom Formatter with the Formatter type
**or with `FormatterResultObject` instead of a string**
184
+
#### Example with `FormatterResultObject` instead of a string
182
185
183
186
Using this object return type will provide the user the same look and feel, it will actually be quite different. The major difference is that all of the options (`addClasses`, `tooltip`, ...) will be added the CSS container of the cell instead of the content of that container. For example a typically cell looks like the following `<divclass="slick-cell l4 r4">Task4</div>` and if use `addClasses: 'red'`, it will end up being `<div class="slick-cell l4 r4 red">Task 4</div>` while if we use a string output of let say `<spanclass="red">${value></span>`, then our final result of the cell will be `<divclass="slick-cell l4 r4"><spanclass="red">Task 4</span></div>`. This can be useful if you plan to use multiple Formatters and don't want to lose or overwrite the previous Formatter result (wedothatinourproject).
> **Note** you could also use our helper `createDomElement` which allows to create a DOM element and pass properties like `className` in 1 liner (and it also works with intellisense). For example `createDomElement('span', { className: 'bold title', textContent: 'Hello World', title: 'some tooltip description' })` would equal to 4 lines of code.
214
+
191
215
#### More Complex Example
192
216
193
217
If you need to add more complex logic to a `Formatter`, you can take a look at the [percentCompleteBar](../../ghiscoding/angular-slickgrid/blob/master/src/app/modules/angular-slickgrid/formatters/percentCompleteBarFormatter.ts) `Formatter` for more inspiration.
0 commit comments