dosubot[bot] commented on issue #29140:
URL: https://github.com/apache/superset/issues/29140#issuecomment-2157813604

   <!-- Answer -->
   To pass the `formatNumber` function into the `embedDashboard` function, you 
can integrate it directly within the dashboard embedding logic. Here's an 
example of how to do this:
   
   1. **Import the `formatNumber` function** from `@superset-ui/core`.
   2. **Define the `formatNumberValue` function** to format numbers using the 
desired format.
   3. **Use the `formatNumberValue` function** within the `embedDashboard` 
logic.
   
   Here is the complete example:
   
   ```ts
   import { embedDashboard } from "@superset-ui/embedded-sdk";
   import { formatNumber } from '@superset-ui/core'; // Ensure you have the 
correct import
   
   async function fetchGuestTokenFromBackend() {
     // Implement the logic to fetch the guest token from your backend
     const response = await fetch('/your-backend-endpoint-to-get-guest-token');
     const data = await response.json();
     return data.guestToken;
   }
   
   function embedCustomDashboard() {
     const currencyFormat = ',.2f'; // Define your desired format
   
     function formatNumberValue(value) {
       return formatNumber(currencyFormat, value);
     }
   
     embedDashboard({
       id: "abc123", // Replace with your actual dashboard ID
       supersetDomain: "https://superset.example.com";, // Replace with your 
Superset domain
       mountPoint: document.getElementById("my-superset-container"), // Replace 
with your actual mount point
       fetchGuestToken: fetchGuestTokenFromBackend,
       dashboardUiConfig: {
         hideTitle: true,
         filters: {
           expanded: true,
         },
         urlParams: {
           foo: 'value1',
           bar: 'value2',
           // Add other URL parameters as needed
         }
       },
       onDataLoad: (data) => {
         // Example usage of formatNumberValue within the dashboard embedding 
logic
         data.forEach(item => {
           item.formattedValue = formatNumberValue(item.value);
         });
         console.log(data); // This will print the formatted data
       }
     });
   }
   
   embedCustomDashboard();
   ```
   
   In this example:
   - The `formatNumber` function is used to format numbers according to the 
specified `currencyFormat`.
   - The `onDataLoad` callback in the `embedDashboard` function processes the 
data and applies the custom number formatting.
   
   This approach ensures that the currency format is correctly applied within 
the embedded dashboard 
<sup>[[1]](https://github.com/apache/superset/blob/master/superset-frontend/packages/superset-ui-core/src/currency-format/utils.ts)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/superset-frontend/packages/superset-ui-core/src/number-format/NumberFormatterRegistrySingleton.ts)</sup>.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to