# UI table formatter If Else creates broken sort

**URL:** <https://discourse.nodered.org/t/ui-table-formatter-if-else-creates-broken-sort/81061>\
**Category:** General\
**Tags:** node-red-dashboard\
**Created:** [5 September 2023 19:02 UTC](https://discourse.nodered.org/t/ui-table-formatter-if-else-creates-broken-sort/81061 "2023-09-05T19:02:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)\
**Post date:** [5 September 2023 19:02 UTC](https://discourse.nodered.org/t/ui-table-formatter-if-else-creates-broken-sort/81061/1 "2023-09-05T19:02:01Z")

</div>

Hello, if I use the following If Else statement in my msg.ui\_control I get the expected result but the table is broken and doesn't display all the rows and is only able to sort in one direction. The other direction creates a blank table.

```auto
            {
                "title": "State",
                "field": "collectionState",
                "formatter": "function(cell, formatterParams, onRendered){var value = cell.getValue();if(value.includes('Normal')){return `<span style='color:#3FB449; font-weight:bold;'>` + value + `</span>`;}else {return `<span style='color:#ff0000; font-weight:bold;'>` + value + `</span>`;}}",
                "width": 100,
                "align": "center"
            },

```

---

<div class="post-metadata">

**Author:** ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)\
**Post date:** [5 September 2023 19:21 UTC](https://discourse.nodered.org/t/ui-table-formatter-if-else-creates-broken-sort/81061/2 "2023-09-05T19:21:24Z")

</div>

Looks like I had some undefined values. Correct code is below:

```auto
            {
                "title": "State",
                "field": "collectionState",
                "formatter": "function(cell, formatterParams, onRendered){var value = cell.getValue();if (value !== undefined) {value = value}else {value = ' '};if(value.includes('Normal')){return `<span style='color:#3FB449; font-weight:bold;'>` + value + `</span>`;}else {return `<span style='color:#ff0000; font-weight:bold;'>` + value + `</span>`;}}",
                "width": 100,
                "align": "center"
            },

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [19 September 2023 19:21 UTC](https://discourse.nodered.org/t/ui-table-formatter-if-else-creates-broken-sort/81061/3 "2023-09-19T19:21:35Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
