Having trouble getting help?
Contact Support
Contact Support
Hide specific columns in Vue Pivotview component
11 Jun 20245 minutes to read
By using the columnRender
event in the gridSettings
, you can hide specific column(s) in the pivot table. In the example below, the “Units Sold” column under “FY 2016” is hidden by setting its visible property to false via the columnRender
event.
NOTE
The dot(.) character in FY 2016.Units Sold is used by default to identify the header levels in the pivot table’s row and column. It can be changed by setting the
headerCellInfo
in thequeryCellInfo
property to any other delimiter instead of the default separator.
<template>
<div id="app">
<ejs-pivotview id="pivotview" :dataSourceSettings="dataSourceSettings" :height="height"
:gridSettings="gridSettings"></ejs-pivotview>
</div>
</template >
<script setup>
import { PivotViewComponent as EjsPivotview } from "@syncfusion/ej2-vue-pivotview";
import { pivotData } from './pivotData.js';
const dataSourceSettings = {
dataSource: pivotData,
expandAll: false,
rows: [{ name: 'Country' }, { name: 'Products' }],
columns: [{ name: 'Year', caption: 'Production Year' }, { name: 'Quarter' }],
values: [{ name: 'Amount', caption: 'Sold Amount' }, { name: 'Sold', caption: 'Units Sold' }],
formatSettings: [{ name: 'Amount', format: 'C0' }],
};
const height = 350;
const gridSettings = {
columnRender(args) {
for (var i = 1; i < args.columns.length; i++) {
if (args.stackedColumns[i].customAttributes &&
args.stackedColumns[i].customAttributes.cell.valueSort.levelName === 'FY 2016.Units Sold') {
args.stackedColumns[i].visible = false;
}
}
}
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";
</style>
<template>
<div id="app">
<ejs-pivotview id="pivotview" :dataSourceSettings="dataSourceSettings" :height="height"
:gridSettings="gridSettings"></ejs-pivotview>
</div>
</template >
<script>
import { PivotViewComponent } from "@syncfusion/ej2-vue-pivotview";
import { pivotData } from './pivotData.js';
export default {
name: "App",
components: {
"ejs-pivotview": PivotViewComponent
},
data() {
return {
dataSourceSettings: {
dataSource: pivotData,
expandAll: false,
rows: [{ name: 'Country' }, { name: 'Products' }],
columns: [{ name: 'Year', caption: 'Production Year' }, { name: 'Quarter' }],
values: [{ name: 'Amount', caption: 'Sold Amount' }, { name: 'Sold', caption: 'Units Sold' }],
formatSettings: [{ name: 'Amount', format: 'C0' }],
},
height: 350,
gridSettings: {
columnRender: function (args) {
for (var i = 1; i < args.columns.length; i++) {
if (args.stackedColumns[i].customAttributes &&
args.stackedColumns[i].customAttributes.cell.valueSort.levelName === 'FY 2016.Units Sold') {
args.stackedColumns[i].visible = false;
}
}
}
},
}
},
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";
</style>