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 update the title of the widget. Attached is the image of the example I am trying to achieve. So if the user picks Years or Months or Days then the title will change by Number of Orders by Years/Months/Days Respectively
I have attempt to create code that would affect the widget title listening to dynamicGranSwap from the Action we created from the above post but to no avail.
widget.on('ready', function(w) {
function updateTitle(granularity) {
let granularityLabel = {
"years": "Year",
"quarters": "Quarter",
"months": "Month",
"weeks": "Week",
"days": "Day"
};
let newTitle = `Number of Orders by ${granularityLabel[granularity]}`;
console.log("Updating Title to:", newTitle); // Debugging
w.title = newTitle;
w.refresh();
}
prism.$scope.$on("dynamicGranSwap", function(event, data) {
console.log("Received Granularity Change:", data); // Debugging
if (data && data.dategran) {
updateTitle(data.dategran);
}
});
updateTitle("weeks");
});Any suggestions DRay Liliia_DevX rapidbisupport harikm007
Rafael Ferreira
Posted 1 year ago·Last reply 1 year ago
5 comments
Rafael Ferreira
OP1 year agoI 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.
DRay
·1 year agoNice solution! Thank you for the update.
Rafael Ferreira
OP1 year agoDRay did you just copy and paste my response? I am very confused by this response
DRay
·1 year agoWell, it does look like the AI copied your code and provided it as a response. Clearly, there is some more work to do there.
Sorry about that. I'll dig into this a bit more and get you a better response.
DRay
·1 year agoHi Astroraf,
Thank you for reaching out!
Full disclosure, this is an AI generated response from an internal tool. Can you let us know if it helps?
To update the title of a widget based on the selected date granularity using BloX, you can use the provided script with some adjustments. The script listens for the "dynamicGranSwap" event and updates the widget title accordingly. Here is a refined version of your script:
widget.on('ready', function(w) { function updateTitle(granularity) { let granularityLabel = { "years": "Year", "quarters": "Quarter", "months": "Month", "weeks": "Week", "days": "Day" }; let newTitle = `Number of Orders by ${granularityLabel[granularity]}`; console.log("Updating Title to:", newTitle); // Debugging w.title = newTitle; w.refresh(); } prism.$scope.$on("dynamicGranSwap", function(event, data) { console.log("Received Granularity Change:", data); // Debugging if (data && data.dategran) { updateTitle(data.dategran); } }); updateTitle("weeks"); });Ensure that the event "dynamicGranSwap" is correctly triggered with the appropriate data structure. The script assumes that the event data contains a property
dategranwhich specifies the granularity selected by the user. If the event is not firing or the data structure is incorrect, you might need to verify the BloX configuration or the event setup in your dashboard.