Movatterモバイル変換


[0]ホーム

URL:


PDF
Edit
Suggest a Feature

    Number formatting in Vue Pivotview component

    7 Jun 202424 minutes to read

    Allows you to specify the required display format that should be used in values of the pivot table. Supported display formats are:

    • Number
    • Currency
    • Percentage
    • Custom

    You can apply format for the numeric values using the following properties in theformatSettings.

    • name: It allows to specify the field name.
    • format: It allows to specify the format of the respective field.

    Possible formatting values are:

    1. N - denotes numeric type.
    2. C - denotes currency type.
    3. P - denotes percentage type.

    If no format is specified it takes number as default format type.

    Other properties include:

    • useGrouping: It allows to enable or disable the separator, for example, $100,000,000 or $100000000 respectively. By default, it will be set astrue.
    • currency: It allows to set the currency code which needs to considered for the currency formatting.
    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showFieldList="showFieldList"></ejs-pivotview></div></template><scriptsetup>import{provide}from"vue";import{PivotViewComponentasEjsPivotview,FieldList}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'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C2',useGrouping:false,currency:'EUR'}],filters:[]};constheight=350;constshowFieldList=true;provide('pivotview',[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"></ejs-pivotview></div></template><script>import{PivotViewComponent,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,drilledMembers:[{name:'Country',items:['France']}],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:'C2',useGrouping:false,currency:'EUR'}],filters:[]},height:350,showFieldList:true}},provide:{pivotview:[FieldList]}}</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>

    You can also format the values at runtime using the formatting dialog. This option can be enabled by setting theallowNumberFormatting property totrue. The same has been discussed in some of the upcoming topics.

    To use the formatting dialog, inject theNumberFormatting module into the pivot table.

    Custom format

    You can add any custom format directly to theformat property in theformatSettings. Custom format can be achieved by using one or more format specifiers listed in the below table.

    SpecifierDescriptionInputFormat Output
    0Replaces the zero with the corresponding digit if it is present. Otherwise, zero will appear in the result string.{ format: ‘0000’ }‘0123’
    #Replaces the ‘ # ‘ symbol with the corresponding digit if it is present. Otherwise, no digits will appear in the result string.{ format: ‘####’ }‘1234’
    .Denotes the number of digits permitted after the decimal point.{ format: ‘###0.##0#’ }‘546321.000’
    %Percent specifier denotes the percentage type format.{ format: ‘0000 %’ }‘0100 %’
    $Denotes the currency type format that is based on the global currency code specified.{ format: ‘$ ###.00’ }’$ 13.00’
    ;Denotes separate formats for positive, negative and zero values.{ format: ‘###.##;(###.00);-0’ }‘(120.00)’
    ‘String’ (single Quotes)Denotes the characters that are enclosed in the single quote (‘) to be replaced in the resulting string.{ format: “####.00 ‘@’” }“123.00 @”

    NOTE: If custom format is defined, certain properties such asuseGrouping andcurrency will not be considered.

    <template><divid="app"><ejs-pivotview:dataSourceSettings="dataSourceSettings":height="height":showFieldList="showFieldList"></ejs-pivotview></div></template><scriptsetup>import{provide}from"vue";import{PivotViewComponentasEjsPivotview,FieldList}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'},{name:'Amount',caption:'Sold Amount'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Sold',format:"####.00 'Nos'"}],filters:[]};constheight=350;constshowFieldList=true;provide('pivotview',[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"></ejs-pivotview></div></template><script>import{PivotViewComponent,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,drilledMembers:[{name:'Country',items:['France']}],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:'Sold',format:"####.00 'Nos'"}],filters:[]},height:350,showFieldList:true}},provide:{pivotview:[FieldList]}}</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>

    Toolbar

    You can enable formatting dialog option in the toolbar by addingNumberFormatting in thetoolbar. After that, you can see the option to invoke the formatting dialog in the toolbar.

    <template><divid="app"><ejs-pivotviewid="pivotview"ref="pivotview":dataSourceSettings="dataSourceSettings":gridSettings="gridSettings":height="height":allowExcelExport="allowExcelExport":allowConditionalFormatting="allowConditionalFormatting":allowPdfExport="allowPdfExport":showToolbar="showToolbar":allowNumberFormatting="allowNumberFormatting":allowCalculatedField="allowCalculatedField":showFieldList="showFieldList":toolbar="toolbar":saveReport="saveReport":loadReport="loadReport":fetchReport="fetchReport":renameReport="renameReport":removeReport="removeReport":newReport="newReport":displayOption="displayOption"></ejs-pivotview></div></template><scriptsetup>import{provide}from"vue";import{PivotViewComponentasEjsPivotview,FieldList,CalculatedField,Toolbar,PDFExport,ExcelExport,ConditionalFormatting,NumberFormatting}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;constgridSettings={columnWidth:140};constallowExcelExport=true;constallowConditionalFormatting=true;constallowNumberFormatting=true;constallowPdfExport=true;constdisplayOption={view:'Both'};constshowToolbar=true;constallowCalculatedField=true;constshowFieldList=true;consttoolbar=["New","Save","SaveAs","Rename","Remove","Load","Grid","Chart","Export","SubTotal","GrandTotal","ConditionalFormatting","NumberFormatting","FieldList"];constsaveReport=(args)=>{letreports=[];letisSaved=false;if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){reports=JSON.parse(localStorage.pivotviewReports);}if(args.report&&args.reportName&&args.reportName!==""){reports.map(function(item){if(args.reportName===item.reportName){item.report=args.report;isSaved=true;}});if(!isSaved){reports.push(args);}localStorage.pivotviewReports=JSON.stringify(reports);}};constfetchReport=(args)=>{letreportCollection=[];letreeportList=[];if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){reportCollection=JSON.parse(localStorage.pivotviewReports);}reportCollection.map(function(item){reeportList.push(item.reportName);});args.reportName=reeportList;};constloadReport=(args)=>{letpivotGridObj=document.getElementById('pivotview').ej2_instances[0];letreportCollection=[];if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){reportCollection=JSON.parse(localStorage.pivotviewReports);}reportCollection.map(function(item){if(args.reportName===item.reportName){args.report=item.report;}});if(args.report){pivotGridObj.dataSourceSettings=JSON.parse(args.report).dataSourceSettings;}};constremoveReport=(args)=>{letreportCollection=[];if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){reportCollection=JSON.parse(localStorage.pivotviewReports);}for(leti=0;i<reportCollection.length;i++){if(reportCollection[i].reportName===args.reportName){reportCollection.splice(i,1);}}if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){localStorage.pivotviewReports=JSON.stringify(reportCollection);}};constrenameReport=(args)=>{letreportCollection=[];if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){reportCollection=JSON.parse(localStorage.pivotviewReports);}reportCollection.map(function(item){if(args.reportName===item.reportName){item.reportName=args.rename;}});if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){localStorage.pivotviewReports=JSON.stringify(reportCollection);}};constnewReport=()=>{letpivotGridObj=document.getElementById('pivotview').ej2_instances[0];pivotGridObj.setProperties({dataSourceSettings:{columns:[],rows:[],values:[],filters:[]}},false);};provide('pivotview',[FieldList,CalculatedField,Toolbar,PDFExport,ExcelExport,ConditionalFormatting,NumberFormatting]);</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>
    <template><divid="app"><ejs-pivotviewid="pivotview"ref="pivotview":dataSourceSettings="dataSourceSettings":gridSettings="gridSettings":height="height":allowExcelExport="allowExcelExport":allowConditionalFormatting="allowConditionalFormatting":allowPdfExport="allowPdfExport":showToolbar="showToolbar":allowNumberFormatting="allowNumberFormatting":allowCalculatedField="allowCalculatedField":showFieldList="showFieldList":toolbar="toolbar":saveReport="saveReport":loadReport="loadReport":fetchReport="fetchReport":renameReport="renameReport":removeReport="removeReport":newReport="newReport":displayOption="displayOption"></ejs-pivotview></div></template><script>import{PivotViewComponent,FieldList,CalculatedField,Toolbar,PDFExport,ExcelExport,ConditionalFormatting,NumberFormatting}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,gridSettings:{columnWidth:140},allowExcelExport:true,allowConditionalFormatting:true,allowNumberFormatting:true,allowPdfExport:true,displayOption:{view:'Both'},showToolbar:true,allowCalculatedField:true,showFieldList:true,toolbar:["New","Save","SaveAs","Rename","Remove","Load","Grid","Chart","Export","SubTotal","GrandTotal","ConditionalFormatting","NumberFormatting","FieldList"]};},methods:{saveReport:function(args){letreports=[];letisSaved=false;if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){reports=JSON.parse(localStorage.pivotviewReports);}if(args.report&&args.reportName&&args.reportName!==""){reports.map(function(item){if(args.reportName===item.reportName){item.report=args.report;isSaved=true;}});if(!isSaved){reports.push(args);}localStorage.pivotviewReports=JSON.stringify(reports);}},fetchReport:function(args){letreportCollection=[];letreeportList=[];if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){reportCollection=JSON.parse(localStorage.pivotviewReports);}reportCollection.map(function(item){reeportList.push(item.reportName);});args.reportName=reeportList;},loadReport:function(args){letpivotGridObj=document.getElementById('pivotview').ej2_instances[0];letreportCollection=[];if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){reportCollection=JSON.parse(localStorage.pivotviewReports);}reportCollection.map(function(item){if(args.reportName===item.reportName){args.report=item.report;}});if(args.report){pivotGridObj.dataSourceSettings=JSON.parse(args.report).dataSourceSettings;}},removeReport:function(args){letreportCollection=[];if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){reportCollection=JSON.parse(localStorage.pivotviewReports);}for(leti=0;i<reportCollection.length;i++){if(reportCollection[i].reportName===args.reportName){reportCollection.splice(i,1);}}if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){localStorage.pivotviewReports=JSON.stringify(reportCollection);}},renameReport:function(args){letreportCollection=[];if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){reportCollection=JSON.parse(localStorage.pivotviewReports);}reportCollection.map(function(item){if(args.reportName===item.reportName){item.reportName=args.rename;}});if(localStorage.pivotviewReports&&localStorage.pivotviewReports!==""){localStorage.pivotviewReports=JSON.stringify(reportCollection);}},newReport:function(){letpivotGridObj=document.getElementById('pivotview').ej2_instances[0];pivotGridObj.setProperties({dataSourceSettings:{columns:[],rows:[],values:[],filters:[]}},false);},},provide:{pivotview:[FieldList,CalculatedField,Toolbar,PDFExport,ExcelExport,ConditionalFormatting,NumberFormatting]}}</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>

    Invoking formatting dialog through external button

    You can invoke the formatting dialog by clicking an external button using theShowNumberFormattingDialog method.

    <template><divid="app"><ejs-buttonid="calculated-field-btn":isPrimary="isPrimary"v-on:click="btnClick">Calculated Field</ejs-button><ejs-pivotviewid="pivotview":height="height":dataSourceSettings="dataSourceSettings":allowCalculatedField="allowCalculatedField"></ejs-pivotview></div></template><scriptsetup>import{provide}from"vue";import{PivotViewComponentasEjsPivotview,CalculatedField,NumberFormatting}from"@syncfusion/ej2-vue-pivotview";import{ButtonComponentasEjsButton}from"@syncfusion/ej2-vue-buttons";import{pivotData}from'./pivotData.js';constdataSourceSettings={dataSource:pivotData,expandAll:false,enableSorting:true,drilledMembers:[{name:'Country',items:['France']}],columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'},{name:'Total',caption:'Total Amount',type:'CalculatedField'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[],calculatedFieldSettings:[{name:'Total',formula:'"Sum(Amount)"+"Sum(Sold)"'}]};constheight=320;constallowCalculatedField=true;constisPrimary=true;constbtnClick=()=>{letpivotGridObj=document.getElementById('pivotview').ej2_instances[0];pivotGridObj.numberFormattingModule.showNumberFormattingDialog();};provide('pivotview',[CalculatedField,NumberFormatting]);</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>
    <template><divid="app"><ejs-buttonid="calculated-field-btn":isPrimary="isPrimary"v-on:click="btnClick">Calculated Field</ejs-button><ejs-pivotviewid="pivotview":height="height":dataSourceSettings="dataSourceSettings":allowCalculatedField="allowCalculatedField"></ejs-pivotview></div></template><script>import{PivotViewComponent,CalculatedField,NumberFormatting}from"@syncfusion/ej2-vue-pivotview";import{ButtonComponent}from"@syncfusion/ej2-vue-buttons";import{pivotData}from'./pivotData.js';exportdefault{name:"App",components:{"ejs-button":ButtonComponent,"ejs-pivotview":PivotViewComponent},data(){return{dataSourceSettings:{dataSource:pivotData,expandAll:false,enableSorting:true,drilledMembers:[{name:'Country',items:['France']}],columns:[{name:'Year',caption:'Production Year'},{name:'Quarter'}],values:[{name:'Sold',caption:'Units Sold'},{name:'Amount',caption:'Sold Amount'},{name:'Total',caption:'Total Amount',type:'CalculatedField'}],rows:[{name:'Country'},{name:'Products'}],formatSettings:[{name:'Amount',format:'C0'}],filters:[],calculatedFieldSettings:[{name:'Total',formula:'"Sum(Amount)"+"Sum(Sold)"'}]},height:320,allowCalculatedField:true,isPrimary:true}},methods:{btnClick:function(){letpivotGridObj=document.getElementById('pivotview').ej2_instances[0];pivotGridObj.numberFormattingModule.showNumberFormattingDialog();}},provide:{pivotview:[CalculatedField,NumberFormatting]}}</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>

    Events

    NumberFormatting

    The event numberFormatting fires while closing the number formatting dialog on “OK” button click. It allows the user to restrict the customization settings done by the user. It has the following parameters

    • formatName: It holds the name of the field.

    • formatSettings: It holds theformatSettings property of the pivot report.

    • cancel: It is a boolean property and by setting this to true , the customization done in number formatting dialog won’t be applied.

    In the below sample, the customization done in number formatting dialog for the field “Amount” won’t be applied.

    <template><divid="app"><ejs-buttonid="calculated-field-btn":isPrimary="isPrimary"v-on:click="btnClick">Number Formatting</ejs-button><ejs-pivotviewid="pivotview":height="height":dataSourceSettings="dataSourceSettings":showFieldList="showFieldList":allowNumberFormatting="allowNumberFormatting":numberFormatting="numberFormatting"></ejs-pivotview></div></template><scriptsetup>import{provide}from"vue";import{PivotViewComponentasEjsPivotview,NumberFormatting,FieldList}from"@syncfusion/ej2-vue-pivotview";import{ButtonComponentasEjsButton}from"@syncfusion/ej2-vue-buttons";import{pivotData}from'./pivotData.js';constdataSourceSettings={dataSource:pivotData,expandAll:false,enableSorting:true,formatSettings:[{name:'Amount',format:'C2',useGrouping:false,currency:'EUR'}],drilledMembers:[{name:'Country',items:['France','Germany']}],columns:[{name:'Year'}],rows:[{name:'Country'},{name:'Products'}],values:[{name:'Amount',caption:'Sold Amount'},{name:'Sold',caption:'Units Sold'}],filters:[]};constheight=350;constshowFieldList=true;constallowNumberFormatting=true;constisPrimary=true;constbtnClick=()=>{letpivotGridObj=document.getElementById('pivotview').ej2_instances[0];pivotGridObj.numberFormattingModule.showNumberFormattingDialog();};constnumberFormatting=(args)=>{if(args.formatName==='Amount'){args.cancel=true;}};provide('pivotview',[NumberFormatting,FieldList]);</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>
    <template><divid="app"><ejs-buttonid="calculated-field-btn":isPrimary="isPrimary"v-on:click="btnClick">Number Formatting</ejs-button><ejs-pivotviewid="pivotview":height="height":dataSourceSettings="dataSourceSettings":showFieldList="showFieldList":allowNumberFormatting="allowNumberFormatting":numberFormatting="numberFormatting"></ejs-pivotview></div></template><script>import{PivotViewComponent,NumberFormatting,FieldList}from"@syncfusion/ej2-vue-pivotview";import{ButtonComponent}from"@syncfusion/ej2-vue-buttons";import{pivotData}from'./pivotData.js';exportdefault{name:"App",components:{"ejs-button":ButtonComponent,"ejs-pivotview":PivotViewComponent},data(){return{dataSourceSettings:{dataSource:pivotData,expandAll:false,enableSorting:true,formatSettings:[{name:'Amount',format:'C2',useGrouping:false,currency:'EUR'}],drilledMembers:[{name:'Country',items:['France','Germany']}],columns:[{name:'Year'}],rows:[{name:'Country'},{name:'Products'}],values:[{name:'Amount',caption:'Sold Amount'},{name:'Sold',caption:'Units Sold'}],filters:[]},height:350,showFieldList:true,allowNumberFormatting:true,isPrimary:true,}},methods:{btnClick:function(){letpivotGridObj=document.getElementById('pivotview').ej2_instances[0];pivotGridObj.numberFormattingModule.showNumberFormattingDialog();},numberFormatting:function(args){if(args.formatName==='Amount'){args.cancel=true;}},provide:{pivotview:[NumberFormatting,FieldList]}}}</script><style>@import"../node_modules/@syncfusion/ej2-vue-pivotview/styles/material.css";</style>

    See Also

    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