Good afternoon,
I'm creating a pivot table in a Vue 3 component.
I was wondering if it's possible to achieve something similar to the column template functionality available in DataGrid, but specifically for a Pivot Table?
I'd like to add an extra column to my pivot table to insert action buttons (such as an "Edit" button).
Here's my code sample:
Thank you for your help.
Antoine
Hi Antoine,
Thank you for sharing the code example. We understand that you need to add a new column to a pivot table and include a button within the value cells of this column using the cellTemplate option. If this is the case, add a calculated field with a dummy formula to add a new column and then add a buttons to that value cells of this calculated field column. And ensure that the cellTemplate option is bound using the Vue <template> tag with a v-slot directive. Within the template tag, include a button and bind the click event to carry out further actions based on the clicked cell. Please see the code example below.
Code example:
|
<template> <div> <div class="control-section"> <div class="content-wrapper"> <ejs-pivotview id="pivotview" :dataSourceSettings="dataSourceSettings" :gridSettings="gridSettings" :width="width" :height="height" :cellTemplate="'myTemplate'" > <template v-slot:myTemplate="{ data }"> <span class="template-wrap"> <button v-if="isTotalColumn(data)" class="btn btn-primary" @click="handleButtonClick(data.cellInfo)" > Click Me </button> </span> </template> </ejs-pivotview> </div> </div> </div> </template> <script lang="ts"> export default { methods: { isTotalColumn(args) { if (args.cellInfo.axis === "value" && args.cellInfo.actualText === "Total") { // Remove the existing text if (args.targetCell) { args.targetCell.querySelector('.e-cellvalue').innerText = ''; } return true; } return false; }, handleButtonClick(cellInfo) { console.log('Button clicked with cell info:', cellInfo); }, } }; </script> |
Output screenshot:
Meanwhile, we have prepared a sample for your reference, which is available at the following link:
Sample: https://stackblitz.com/edit/p3nbuvqz-qwrgsy7e?file=src%2FApp.vue
Please let us know if you have any concerns.
Regards,
Sridhar Karunakaran