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

   <!-- Answer -->
   To convert the currency format and fetch data from your customized Super 
Dashboard page using the `superset-ui/embedded-sdk`, follow these steps:
   
   1. **Convert Currency Format:**
      Use JavaScript to convert the number format. Here is a function to 
achieve this:
   
      ```js
      function convertNumberFormat(numberString) {
        // Remove the currency symbol
        let number = numberString.replace('₫', '').trim();
        
        // Replace commas with temporary placeholder
        number = number.replace(/,/g, '_');
        
        // Replace dots with commas
        number = number.replace(/\./g, ',');
        
        // Replace temporary placeholder with dots
        number = number.replace(/_/g, '.');
        
        // Add the currency symbol back
        return number + '₫';
      }
   
      const formattedNumber = convertNumberFormat("226,049,182,616.69₫");
      console.log(formattedNumber); // Output: "226.049.182.616,69₫"
      ```
   
   2. **Fetch Data from Customized Super Dashboard:**
      Use the `embedDashboard` function from the `superset-ui/embedded-sdk` to 
embed and fetch data from your customized Super Dashboard page. Here is an 
example:
   
      ```js
      import { embedDashboard } from "@superset-ui/embedded-sdk";
   
      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;
      }
   
      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
          }
        },
      });
      ```
   
   Additionally, you can leverage the `NumberFormatterRegistrySingleton` from 
`superset-ui-core` to handle number formatting more robustly:
   
   ```ts
   import { getNumberFormatter, setD3Format } from '@superset-ui/core';
   
   // Define a custom locale for number formatting
   const customLocale = {
     decimal: ',',
     thousands: '.',
     grouping: [3],
     currency: ['₫', ''],
   };
   
   // Set the custom locale
   setD3Format(customLocale);
   
   // Get the formatter
   const formatter = getNumberFormatter(',.2f');
   
   // Format the number
   const formattedNumber = formatter(226049182616.69);
   console.log(formattedNumber); // Output: "226.049.182.616,69₫"
   ```
   
   By following these steps, you can convert the currency format and embed your 
customized Super Dashboard page using the `superset-ui/embedded-sdk` 
<sup>[[1]](https://github.com/apache/superset/blob/master/superset-embedded-sdk/README.md)</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: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to