Astroraf
03-13-2025Data Pipeline
Date Granularity Affecting Title Widget
I am using this solution from intapiuser: https://community.sisense.com/t5/knowledge-base/change-date-granularity-of-a-widget-using-blox/ta-p/8916 to try and get a widget that this BloX affects to up...
- 03-13-2025
I found a solution:
You can provide exact titles that you want to update on your side, then set a timeout so that the title updates with what you choose.
// Holds the chosen granularity from the selected button, e.g., 'months' const dategran = payload.dategran; var widgetIds = payload.data.widgetToModify; // Define title mapping const titleMap = { "years": "Number of Orders by Years", "quarters": "Number of Orders by Quarters", "months": "Number of Orders by Months", "weeks": "Number of Orders by Weeks", "days": "Number of Orders by Days" }; // Change the background color for unselected buttons payload.widget.style.currentCard.actions.forEach(function (i) { i.style["background-color"] = '#D3D3D3'; }); // Change the background color for the selected button payload.widget.style.currentCard.actions .filter(i => i.dategran == dategran)[0].style["background-color"] = "#f2B900"; // Redraw the BloX widget to reflect changes payload.widget.redraw(); // For each widget in the affected list, update the granularity first payload.widget.dashboard.widgets.$$widgets .filter(i => widgetIds.includes(i.oid)) .forEach(function (widget) { // Change the X-axis granularity (original working code) widget.metadata.panels[0].items[0].jaql.level = dategran; // Apply changes to update granularity first widget.changesMade('someEvent', ['metadata', 'properties_changed']); // Refresh to ensure the granularity update is applied before changing the title widget.refresh(); // **Ensure title updates AFTER granularity change is applied** setTimeout(() => { widget.title = titleMap[dategran] || "Number of Orders"; widget.changesMade('title_changed'); widget.refresh(); }, 100); // Short delay ensures X-axis granularity update is completed first }); // Emit an event for further dynamic changes if needed prism.$scope.$emit("dynamicGranSwap", { dategran: dategran });