找回密码
 立即注册

QQ登录

只需一步,快速开始

本帖最后由 AlexZ 于 2023-6-15 14:23 编辑

单字段小计位置 / Subtotal Position
新版本中,可以对单字段的小计位置进行设置
pivottable-subtotal-option-for-single-fields-gif-sjs-v16-1-0-release-blog.gif
  1. ///* function subtotalPosition(fieldName: string, position: GC.Spread.Pivot.SubtotalsPosition): GC.Spread.Pivot.SubtotalsPosition
  2.     /**
  3.      * @description set or get field show subtotal position information.
  4.      * @param {string} fieldName Indicates the field name.
  5.      * @param {GC.Spread.Pivot.SubtotalsPosition} position The indicates set whether subtotal position, only top and bottom is supported.
  6.      * @returns {GC.Spread.Pivot.SubtotalsPosition}
  7.      * @example
  8.      * var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
  9.      * var sourceSheet = spread.getSheet(0)
  10.      * var sheet = spread.getSheet(1);
  11.      * var sourceData = [["Date","Buyer","Type","Amount"],
  12.      *                  ["01-Jan","Mom","Fuel",74],
  13.      *                  ["15-Jan","Mom","Food",235],
  14.      *                  ["17-Jan","Dad","Sports",20],
  15.      *                  ["21-Jan","Kelly","Books",125]];
  16.      * sourceSheet.setArray(0, 0, sourceData);
  17.      * sourceSheet.tables.add('sourceData', 0, 0, 5, 4);
  18.      * var layout = GC.Spread.Pivot.PivotTableLayoutType.compact;
  19.      * var theme = GC.Spread.Pivot.PivotTableThemes.medium2;
  20.      * var options = {showRowHeader: true, showColumnHeader: true};
  21.      * sheet.pivotTables.add("pivotTable_1", 'sourceData', 1, 1, layout, theme, options);
  22.      * var pivotTable = sheet.pivotTables.get("pivotTable_1");
  23.      * pivotTable.add("Date","Date",GC.Spread.Pivot.PivotTableFieldType.rowField);
  24.      * pivotTable.add("Buyer","Buyer",GC.Spread.Pivot.PivotTableFieldType.rowField);
  25.      * pivotTable.add("Type","Type",GC.Spread.Pivot.PivotTableFieldType.columnField);
  26.      * pivotTable.add("Amount","Sum of Amount",GC.Spread.Pivot.PivotTableFieldType.valueField, GC.Pivot.SubtotalType.sum);
  27.      * pivotTable.subtotalPosition("Date", GC.Spread.Pivot.SubtotalsPosition.top);
  28.      */
  29.      subtotalPosition (fieldName: string, position?: SubtotalsPosition): SubtotalsPosition {
复制代码

支持对值进行排序 / Sort Value
新版本的数据透视表,支持对数据进行排序,方式与 Excel 保持兼容,如下图所示:
pt-sort.gif

API
  1. /**
  2. * @description get or set sort for a field of pivot table.
  3. * @param {string} fieldName Indicates the target field name.
  4. * @param {GC.Pivot.IPivotViewSortInfo} [sortInfo] Indicates the sort info.
  5. * @returns {GC.Pivot.IPivotViewSortInfo | void}
  6. **/
  7. sort (fieldName: string, sortInfo?: GC.Pivot.IPivotViewSortInfo): GC.Pivot.IPivotViewSortInfo | void
复制代码
示例代码
  1. // sort COUNTRY field by DAMAGE value in ascending order
  2. var sortInfo = {
  3.     sortType: GC.Pivot.SortType.asc,
  4.     sortValueFieldName: "DAMAGE"
  5. };
  6. pivotTable.sort("COUNTRY", sortInfo);

  7. // sort LEVEL field by DAMAGE value of Germany:MT row in descending order
  8. var sortInfo = {
  9.     sortType: GC.Pivot.SortType.desc,
  10.     sortValueFieldName: "DAMAGE",
  11.     sortByPivotReferences: [
  12.         {
  13.             fieldName: "Country",
  14.             items: ["Germany"]
  15.         },
  16.         {
  17.             fieldName: "Type1",
  18.             items: ["MT"]
  19.         }
  20.     ]
  21. };
  22. pivotTable.sort("Level", sortInfo);
复制代码


支持是否使用 GetPivotData 函数开关

新版本中,用户可以通过配置项决定是否对数据透视表的数据引用采用 GetPivotData 函数或者是普通单元格引用,如下图所示:

使用 GetPivotData
image.png762258605.png

使用单元格引用
image.png973050537.png

API:
image.png840599365.png


0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部