Formatting Table Widget
Hi,
I am very new to Sisense and I am struggling with the formatting capabilities of the table widget. I would like to do some basic formatting of the table as follows:
- Format the column header row as bold
- Align certain headers as centre.
- Align certain columns as right aligned.
Am I able to do this within 'Edit Script' and if so, please could someone point me in the right direction?
Kind Regards Carly
bathyphen
Posted 1 year ago·Last reply 1 year ago
3 comments
bathyphen
OP1 year agoThank you so much for your reply.
The only one I can seem to get to work is the columns with numbers in being left-aligned, which is a great start.
Could the issue I have with the bold column headers be because I am using a standard table widget, rather than a pivot table?
DRay
·1 year agoAs an additional FYI,
[widgetid='${widgetID}']at the beginning of a selector, an example of this functionality is:DRay
·1 year agoHello bathyphenm,
Thank you for reaching out, and welcome to the Sisense Community!
This can, indeed, be done with the 'Edit Script' functionality. You can use CSS by wrapping it in Javascript. Here are some example scripts that will help get you started. You may need to tweak them for your specific use-case.
Format the column header row as bold: Use the following script to format the header rows and columns of a Pivot table:
widget.on("ready", function(w, args) { var $ps1 = $(".p-grand-total-head,.p-dim-head", element); $ps1.css('font-weight' , 'bold'); });This script sets the font weight of the header rows to bold [please refer to https://community.sisense.com/t5/knowledge-base/formatting-pivot-header-rows-and-columns-via-css/ta-p/9151 for more info].
Align certain headers as center: You can modify the same script to include text alignment for headers:
widget.on("ready", function(w, args) { var $ps1 = $(".p-grand-total-head,.p-dim-head", element); $ps1.css('font-weight' , 'bold'); $ps1.css('text-align' , 'center'); });This script sets the text alignment of the header rows to center [please refer to https://community.sisense.com/t5/knowledge-base/formatting-pivot-header-rows-and-columns-via-css/ta-p/9151 for more info].
Align certain columns as right aligned: Use the following script to align numeric values to the right:
widget.on('domready', function(se, ev){ const alignNumbersToTheRight = () =>{ $('td', element).each(function(){ if(/^[0-9,.]*$/.test($(this).text())){ $(this).css('text-align', 'right') } }) } alignNumbersToTheRight() const elementToObserve = $('table tbody', element)[0] const observer = new MutationObserver(function(e) { alignNumbersToTheRight() }) observer.observe(elementToObserve, {subtree: true, childList: true}); });This script aligns numeric values to the right in the table widget [please refer to https://community.sisense.com/t5/knowledge-base/align-numeric-values-to-the-right-on-a-table-widget/ta-p/21538 for more info].
By incorporating these scripts into the 'Edit Script' section of your table widget, you can achieve the desired formatting.