Movatterモバイル変換


[0]ホーム

URL:


PDF
Edit
Suggest a Feature

    Aggregation in Vue Pivotview component

    7 Jun 202424 minutes to read

    This feature is applicable only for the relational data source.

    End user can perform calculations over a group of values (exclusively for value fields bound in value axis) using the aggregation option. By default, values are added (summed) together. The other aggregation types are explained below.

    The fields with data type such as number support all aggregation types mentioned below except for“CalculatedField”. The fields with data type such as string, date, datetime, boolean, etc., support“Count” and“DistinctCount” aggregation types alone.

    OperatorDescription
    SumDisplays the pivot table values with sum.
    ProductDisplays the pivot table values with product.
    CountDisplays the pivot table values with count.
    DistinctCountDisplays the pivot table values with distinct count.
    MinDisplays the pivot table with minimum value.
    MaxDisplays the pivot table with maximum value.
    AvgDisplays the pivot table values with average.
    IndexDisplays the pivot table values with index.
    PopulationStDevDisplays the pivot table values with standard deviation of population.
    SampleStDevDisplays the pivot table values with sample standard deviation.
    PopulationVarDisplays the pivot table values with variance of population.
    SampleVarDisplays the pivot table values with sample variance.
    RunningTotalsDisplays the pivot table values with running totals.
    DifferenceFromDisplays the pivot table values with difference from the value of the base item in the base field.
    PercentageOfDifferenceFromDisplays the pivot table values with percentage difference from the value of the base item in the base field.
    PercentageOfGrandTotalDisplays the pivot table values with percentage of grand total of all values.
    PercentageOfColumnTotalDisplays the pivot table values in each column with percentage of total values for the column.
    PercentageOfRowTotalDisplays the pivot table values in each row with percentage of total values for the row.
    PercentageOfParentTotalDisplays the pivot table values with percentage of total of all values based on selected field.
    PercentageOfParentColumnTotalDisplays the pivot table values with percentage of its parent total in each column.
    PercentageOfParentRowTotalDisplays the pivot table values with percentage of its parent total in each row.
    CalculatedFieldDisplays the pivot table with calculated field values. It allows user to create a new calculated field alone.

    Assigning aggregation type for value fields through API

    For each value field, the aggregation type can be set using the propertytype invalues. Meanwhile, aggregation types likeDifferenceFrom andPercentageOfDifferenceFrom can check for specific field of specific item usingbaseField andbaseItem properties. Likewise,PercentageOfParentTotal type can for specific field usingbaseField property. For instance, the aggregation typeDifferenceFrom would intake the specified field and its corresponding member as input and its value is compared across other members in the same field and also across different fields to formulate an appropriate output value.

    • type: It allows to set the aggregate type of the field.
    • baseField: It allows to set the specific field to aggregate the values.
    • baseItem: It allows to set the specific member to aggregate the values.
    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height"></ejs-pivotview></div></template><scriptsetup>import{PivotViewComponentasEjsPivotview}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';constdataSourceSettings={dataSource:pivotData,expandAll:false,drilledMembers:[{name:'Country',items:['France']}],columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold',type:"DifferenceFrom",baseField:"Country",baseItem:"France"},{name:'Amount',caption:'Sold Amount',type:'Sum'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[]};constheight=350;</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>
    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height"></ejs-pivotview></div></template><script>import{PivotviewComponent}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';exportdefault{name:"App",components:{"ejs-pivotview":PivotviewComponent},data(){return{dataSourceSettings:{dataSource:pivotData,expandAll:false,drilledMembers:[{name:'Country',items:['France']}],columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold',type:"DifferenceFrom",baseField:"Country",baseItem:"France"},{name:'Amount',caption:'Sold Amount',type:'Sum'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[]},height:350}}}</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>

    By default, the aggregation will be considered asSum to the value fields which had number type and for the value fields which had non-number type values such as string, date, datetime, boolean, etc., the aggregation type will be considered asCount.

    Modifying aggregation type for value fields at runtime

    Aggregation types can be changed easily through UI at runtime. The value fields bound to grouping bar and field list appears with a dropdown icon which helps to select an appropriate aggregation type for the respective value field. On selection, the values in the pivot table will be changed dynamically.

    output




    output

    Show desired aggregation types in its dropdown menu

    By default, all the aggregation types are displayed in the dropdown menu available in buttons. However, based on the request for an application, we may need to show selective aggregation types on our own. This can be achieved using theaggregateTypes property.

    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showFieldList="showFieldList":showGroupingBar="showGroupingBar":aggregateTypes="aggregateTypes"></ejs-pivotview></div></template><scriptsetup>import{provide}from"vue";import{PivotViewComponentasEjsPivotview,GroupingBar,FieldList}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';constdataSourceSettings={dataSource:pivotData,drilledMembers:[{name:'Country',items:['France']}],columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount',type:'Sum'}],rows:[{name:'Country'},{name:'Products'}],filters:[],};constheight=350;constshowFieldList=true;constshowGroupingBar=true;constaggregateTypes=['DistinctCount','Avg','Product'];provide('pivotview',[GroupingBar,FieldList]);</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>
    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showFieldList="showFieldList":showGroupingBar="showGroupingBar":aggregateTypes="aggregateTypes"></ejs-pivotview></div></template><script>import{PivotViewComponent,GroupingBar,FieldList}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';exportdefault{name:"App",components:{"ejs-pivotview":PivotViewComponent},data(){return{dataSourceSettings:{dataSource:pivotData,drilledMembers:[{name:'Country',items:['France']}],columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount',type:'Sum'}],rows:[{name:'Country'},{name:'Products'}],filters:[],},height:350,showFieldList:true,showGroupingBar:true,aggregateTypes:['DistinctCount','Avg','Product']}},provide:{pivotview:[GroupingBar,FieldList]}}</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>

    Hiding aggregation type from button text

    By default, in value axis each field would be displayed by its name and aggregation type together. To hide aggregation type and display field name alone, set the propertyshowAggregationOnValueField indataSourceSettings tofalse.

    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showGroupingBar="showGroupingBar"></ejs-pivotview></div></template><scriptsetup>import{provide}from"vue";import{PivotViewComponentasEjsPivotview,GroupingBar}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';constdataSourceSettings={dataSource:pivotData,expandAll:false,columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[],showAggregationOnValueField:false};constheight=350;constshowGroupingBar=true;provide('pivotview',[GroupingBar]);</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>
    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showGroupingBar="showGroupingBar"></ejs-pivotview></div></template><script>import{PivotViewComponent,GroupingBar}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';exportdefault{name:"App",components:{"ejs-pivotview":PivotViewComponent},data(){return{dataSourceSettings:{dataSource:pivotData,expandAll:false,columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[],showAggregationOnValueField:false},height:350,showGroupingBar:true}},provide:{pivotview:[GroupingBar]}}</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>

    Hiding aggregation type icon from UI

    By default, the icon to set aggregation type is enabled in the grouping bar. To disable this icon, set the propertyshowValueTypeIcon ingroupingBarSettings tofalse.

    Icon to change the aggregation type can be hidden only in Grouping Bar but not in Field List at the moment.

    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showGroupingBar="showGroupingBar":groupingBarSettings="groupingBarSettings"></ejs-pivotview></div></template><scriptsetup>import{provide}from"vue";import{PivotViewComponentasEjsPivotview,GroupingBar}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';constdataSourceSettings={dataSource:pivotData,expandAll:false,columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[],showAggregationOnValueField:false};constheight=350;constshowGroupingBar=true;constgroupingBarSettings={showValueTypeIcon:false};provide('pivotview',[GroupingBar]);</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>
    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showGroupingBar="showGroupingBar":groupingBarSettings="groupingBarSettings"></ejs-pivotview></div></template><script>import{PivotViewComponent,GroupingBar}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';exportdefault{name:"App",components:{"ejs-pivotview":PivotViewComponent},data(){return{dataSourceSettings:{dataSource:pivotData,expandAll:false,columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[],showAggregationOnValueField:false},height:350,showGroupingBar:true,groupingBarSettings:{showValueTypeIcon:false}}},provide:{pivotview:[GroupingBar]}}</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>

    Event

    AggregateCellInfo

    The eventaggregateCellInfo triggers every time while rendering value cell. This allows user to change the cell value and skip formatting if applied. It has following parameters:

    • fieldName - It holds current cell’s field name.
    • row - It holds current cell’s row value.
    • column - It holds current cell’s row value.
    • value - It holds value of current cell.
    • cellSets - It holds raw data for the aggregated value cell.
    • rowCellType - It holds row cell type value.
    • columnCellType - It holds column cell type value.
    • aggregateType - It holds aggregate type of the cell.
    • skipFormatting - boolean property, it allows to skip formatting if applied.
    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":aggregateCellInfo="aggregateCell"></ejs-pivotview></div></template><scriptsetup>import{PivotViewComponentasEjsPivotview}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';constdataSourceSettings={dataSource:pivotData,expandAll:false,columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[],};constheight=350;constaggregateCell=(args)=>{args.skipFormatting=false;};</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>
    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":aggregateCellInfo="aggregateCell"></ejs-pivotview></div></template><script>import{PivotViewComponent}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';exportdefault{name:"App",components:{"ejs-pivotview":PivotViewComponent},data(){return{dataSourceSettings:{dataSource:pivotData,expandAll:false,columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[],},height:350}},methods:{aggregateCell:function(args){args.skipFormatting=false;}}}</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>

    ActionBegin

    The eventactionBegin triggers when clicking and selecting the aggregate type via the dropdown icon in the value field button, which is present in both grouping bar and field list UI. This allows user to identify the current action being performed at runtime. It has the following parameters:

    • dataSourceSettings: It holds the current data source settings such as input data source, rows, columns, values, filters, format settings and so on.

    • actionName: It holds the name of the current action began. For example, while performing aggregation, the action name will be shown asAggregate field.

    • fieldInfo: It holds the selected value field information.

    Note: This option is applicable only when the field based UI actions are performed such as filtering, sorting, removing field from grouping bar, editing and aggregation type change.

    • cancel: It allows user to restrict the current action.

    In the following example, action taken during aggregation type selection via dropdown icon can be restricted by setting theargs.cancel option totrue in theactionBegin event.

    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showGroupingBar="showGroupingBar":actionBegin="actionBegin"></ejs-pivotview></div></template><scriptsetup>import{provide}from"vue";import{PivotViewComponentasEjsPivotview,GroupingBar,FieldList}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';constdataSourceSettings={dataSource:pivotData,expandAll:false,columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[]};constheight=350;constshowGroupingBar=true;constactionBegin=(args)=>{if(args.actionName=='Aggregate field'){args.cancel=true;}};provide('pivotview',[GroupingBar,FieldList]);</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>
    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showGroupingBar="showGroupingBar":actionBegin="actionBegin"></ejs-pivotview></div></template><script>import{PivotViewComponent,GroupingBar,FieldList}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';exportdefault{name:"App",components:{"ejs-pivotview":PivotViewComponent},data(){return{dataSourceSettings:{dataSource:pivotData,expandAll:false,columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[]},height:350,showGroupingBar:true}},methods:{actionBegin:function(args){if(args.actionName=='Aggregate field'){args.cancel=true;}}},provide:{pivotview:[GroupingBar,FieldList]}}</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>

    ActionComplete

    The eventactionComplete triggers when a UI action, such as applying aggregation using the dropdown icon via the value field button, which is present in both the grouping bar and the field list UI, is completed. This allows user to identify the current UI action being completed at runtime. It has the following parameters:

    • dataSourceSettings: It holds the current data source settings such as input data source, rows, columns, values, filters, format settings and so on.

    • actionName: It holds the name of the current action completed. For example, after completing the aggregation, the action name will be shown asField aggregated.

    • fieldInfo: It holds the selected value field information.

    Note: This option is applicable only when the field based UI actions are performed such as filtering, sorting, removing field from grouping bar, editing and aggregation type change.

    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showGroupingBar="showGroupingBar":showFieldList="showFieldList":actionComplete="actionComplete"></ejs-pivotview></div></template><scriptsetup>import{provide}from"vue";import{PivotViewComponentasEjsPivotview,GroupingBar,FieldList}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';constdataSourceSettings={dataSource:pivotData,expandAll:false,columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[]};constheight=350;constshowGroupingBar=true;constshowFieldList=true;constactionComplete=(args)=>{if(args.actionName=='Field aggregated'){// Triggers when the aggregation type is applied.}};provide('pivotview',[GroupingBar,FieldList]);</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>
    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showGroupingBar="showGroupingBar":showFieldList="showFieldList":actionComplete="actionComplete"></ejs-pivotview></div></template><script>import{PivotViewComponent,GroupingBar,FieldList}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';exportdefault{name:"App",components:{"ejs-pivotview":PivotViewComponent},data(){return{dataSourceSettings:{dataSource:pivotData,expandAll:false,columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[]},height:350,showGroupingBar:true,showFieldList:true}},methods:{actionComplete:function(args){if(args.actionName=='Field aggregated'){// Triggers when the aggregation type is applied.}}},provide:{pivotview:[GroupingBar,FieldList]}}</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>

    ActionFailure

    The eventactionFailure triggers when the current UI action fails to achieve the desired result. It has the following parameters:

    • actionName: It holds the name of the current action failed. For example, if the action fails while performing the aggregation, then the action name will be shown asAggregate field.

    • errorInfo: It holds the error information of the current UI action.

    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showGroupingBar="showGroupingBar":showFieldList="showFieldList":actionFailure="actionFailure"></ejs-pivotview></div></template><scriptsetup>import{provide}from"vue";import{PivotViewComponentasEjsPivotview,GroupingBar,FieldList}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';constdataSourceSettings={dataSource:pivotData,expandAll:false,columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[]};constheight=350;constshowGroupingBar=true;constshowFieldList=true;constactionFailure=(args)=>{if(args.actionName=='Aggregate field'){// Triggers when the current UI action fails to achieve the desired result.}};provide('pivotview',[GroupingBar,FieldList]);</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>
    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showGroupingBar="showGroupingBar":showFieldList="showFieldList":actionFailure="actionFailure"></ejs-pivotview></div></template><script>import{PivotViewComponent,GroupingBar,FieldList}from"@syncfusion/ej2-vue-pivotview";import{pivotData}from'./pivotData.js';exportdefault{name:"App",components:{"ejs-pivotview":PivotViewComponent},data(){return{dataSourceSettings:{dataSource:pivotData,expandAll:false,columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[]},height:350,showGroupingBar:true,showFieldList:true}},methods:{actionFailure:function(args){if(args.actionName=='Aggregate field'){// Triggers when the current UI action fails to achieve the desired result.}}},provide:{pivotview:[GroupingBar,FieldList]}}</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>

    Help us improve this page

    Please provide additional information

    Please provide additional information

    Please provide additional information

    Please provide additional information

    Please provide additional information
    Please provide additional information
    ×

    [8]ページ先頭

    ©2009-2025 Movatter.jp