FreedomUI - Format number in list view without commas
Hello,
In the freedom UI section list view, is there a way to format a numeric field so that it shows without commas? The field is an integer field and meant to store an identification number and not a quantity, so we are looking for a way to apply a custom format for the column to just show the digits without commas.
We did try to use a text field, but it doesn't work well because the sorting and filtering treats it as text values.
In classic UI it seemed like there were ways to do this like the post below. Is there something equivalent for FreedomUI?
https://community.creatio.com/questions/change-display-format-section-l…
Like
Hello,
The only possible working way to achieve this was using this code in the section list handlers:
{ request: "crt.LoadDataRequest", handler: async (request, next) => { var allElements = document.getElementsByTagName("td"); for (var i = 0; i < allElements.length; i++) { if (allElements[i].className.indexOf("PDS_UsrIntegCol") != -1) { var valueToReplaceElement = allElements[i].getElementsByClassName("crt-data-table-cell-value ng-star-inserted")[0]; var valueToReplaceValue = valueToReplaceElement.innerText; valueToReplaceElement.innerText = valueToReplaceValue.replace(",", ""); } } return next?.handle(request); } }
you need to replace PDS_UsrIntegCol with PDS_your column code in the code to test. But - it works only on the initial section list load and also sometimes not triggered upon changing the sorting. If someone has a better approach on this topic please share your ideas.
Oleg Drobina,
Is this still the case in Freedom UI? The ability to specify that it should be displayed without thousands separators was available in Classic UI.
It would be very useful if we could specify some of these default formatting options on the entity as well - year fields will always want to be an integer but also want to prevent thousands separators for example, and having to modify every page schema that may display them is not great.
Oleg Drobina, Harvey Adcock,
Below is the updated version to work on the cell content using DOM rendering.
{ request: "crt.LoadDataRequest", handler: async (request, next) => { const result = await next?.handle(request); const COLUMN_CODE = "PDS_UsrIntegCol"; // column code // Scope to the grid if available; fallback to document const grid = document.querySelector('.mat-table[role="grid"]') || document.querySelector('.mat-table') || document; const stripCommas = () => { const tds = grid.getElementsByTagName("td"); for (let i = 0; i < tds.length; i++) { const td = tds[i]; const cls = td.className || ""; if ( cls.indexOf('cdk-column-${COLUMN_CODE}') !== -1 || cls.indexOf(COLUMN_CODE) !== -1 ) { const el = td.querySelector(".crt-data-table-cell-value"); if (!el) continue; const txt = el.textContent || ""; if (txt.indexOf(",") !== -1) { el.textContent = txt.replace(/,/g, ""); } } } }; // Initial pass after data loads stripCommas(); // Re-apply after sort/paging/virtual scroll, then auto-stop const observer = new MutationObserver((mutations) => { for (const m of mutations) { if (m.type === "childList") { requestAnimationFrame(stripCommas); break; } } }); observer.observe(grid, { childList: true, subtree: true }); // Safety: stop observing after a short window setTimeout(() => observer.disconnect(), 5000); return result; } }
Notes:
- Selector is brittle
- You target
.crt-data-table-cell-value ng-star-inserted
. Theng-star-inserted
class is added/removed by Angular and is not reliable. - Use
.crt-data-table-cell-value
only.
- You target
- No re-apply after sort/paging
- Angular re-renders rows on sort/paging/virtual scroll, so your initial pass doesn’t run again.
- Add a short-lived
MutationObserver
on the grid to re-run after those redraws.
- Avoid layout cost & errors
- Prefer
textContent
overinnerText
. - Guard for missing nodes to prevent undefined errors.
- Batch updates with
requestAnimationFrame
and auto-disconnect the observer to avoid leaks.
- Prefer