Cell Template and Copy Pasting

Posted by: ryan on 5 October 2023, 3:28 am EST

  • Posted 5 October 2023, 3:28 am EST

    Is it possible to copy out the [cellTemplate] version of a cell for pasting in Excel. If not can you give me a code snippet to use in the copying method to make this work?

    For example.

    I have a bunch of different currencies being displayed in the same grid and divided by row.

    USD | $123.45 | $123.45

    GBP | £123.45 | £123.45

    EUR | €123.45. | €1213.45

    The values are coming in as numbers (ex. 123.45) and then I’m using cellTemplate to parse out the correct currency for the row and apply the correct CurrencyPipe for each case. I have experimented with using [Format]=“‘c2’” but it assumes all cases are USD.

  • Posted 5 October 2023, 10:36 pm EST

    Hi,

    You need to customize the copying logic to achieve the required functionality. This can be done by handling the copying event of FlexGrid. I have modified the copying logic in the below-shared sample. You may modify this copying logic as per your use case or requirement.

    Also, to format the number as per the currency symbol you need to maintain a mapping for each currency symbol along with the currency name. Then you can pass the numeric value along with the format string to the formatNumber() method of the Globalize class.

    Please refer to this API link for more information on formatNumber() method: https://www.grapecity.com/wijmo/api/classes/wijmo.globalize.html#formatnumber

    Please refer to this sample for reference: https://stackblitz.com/edit/angular-u7rd9m

    Regards,

    Anirudh

  • Posted 6 October 2023, 2:34 am EST

    Thanks for the info.

    Is there an alternative to the [cellTemplate] field? A field that allows you to do formatting which does matter and carry through? I took a look at the "<ng-template wjFlexGridCellTemplate …> formatting as well and this is even less user friendly.

  • Posted 8 October 2023, 6:10 pm EST

    Hi Ryan,

    As per my understanding, you have tried both approaches to provide cellTemplate for the cells present in a column and want to try a different approach in which there is no need to maintain a separate mapping of currencies with their respective symbols.

    If this is the case, then you can handle the formatItem event of the FlexGrid to put formatted data in the cells using the Currency pipe. Then in the handleCopying method, you may raise formatItem event of the FlexGrid and get the formatted value of the cell.

    However, raising the formatItem event for each and every required cell is an expensive approach and might affect performance when copying a large amount of formatted data from FlexGrid.

    In case, if you only want an alternative to the cellTemplate or wjFlexGridCellTemplate then you can handle the formatItem event to provide the formatted data to the cell. In this case, you still need a mapping for the currencies and their symbols as data will be formatted as per that mapping.

    Please refer to this sample for reference: https://stackblitz.com/edit/angular-rgvkur

    The above sample utilizes formatItem event for providing formatted value to the cell and raise formatItem event while copying the cell data.

    Regards

    Anirudh

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels