找回密码
 立即注册

QQ登录

只需一步,快速开始

KevinChen 讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-5-8 18:29  /   查看:2056  /  回复:0
阅读本篇前,推荐先了解透视表镜像区域的概念和接口,详情点击:
《SpreadJS V14 Update1 新特性 - 数据透视表-获取透视表区域(getRange)》

在透视表中,常常需要通过样式来高亮、标记某些区域,或者针对不同的字段、维度来设置不同的样式。
SpreadJS V14 Update1发布之前,需要把样式直接设置在单元格上。
但是样式不会随字段更改发生变化,无法与字段或透视区域产生“联动”效果。

SpreadJS V14 Update1 推出了PivotArea的概念,这样Style可以直接设置在PivotArea上,
自动实现与数据字段联动的效果。如图所示:

spread.gif

代码示例如下:
  1. var AmericaAndBritainStyle = new GC.Spread.Sheets.Style();
  2. AmericaAndBritainStyle.backColor = '#00AFEF';
  3. AmericaAndBritainStyle.foreColor = '#ffffff';
  4. var AmericaAndBritainPivotArea = {
  5.     dataOnly: true,
  6.     references: [{
  7.         fieldName: "Country",
  8.         items: ["America", "Britain"]
  9.     }]
  10. }
  11. pivotTable.setStyle(AmericaAndBritainPivotArea, AmericaAndBritainStyle);
复制代码


API描述如下:

  1. ///* function setStyle (pivotArea: GC.Spread.Pivot.IPivotArea, style: GC.Spread.Sheets.Style): void
  2. /**
  3. * @description 设置或清除指定透视区域的样式.
  4. * @param {GC.Spread.Pivot.IPivotArea} pivotArea 指定的透视区域
  5. * @param {GC.Spread.Sheets.Style} style 要设置的样式对象, 传入 null 或 undefined 可以清除指定透视区域的样式.
  6. */
  7. setStyle (pivotArea: IPivotArea, style: Style): void

  8. ///* function getStyle (pivotArea: GC.Spread.Pivot.IPivotArea): GC.Spread.Sheets.Style
  9. /**
  10. * @description 获取指定区域的样式对象.
  11. * @param {GC.Spread.Pivot.IPivotArea} pivotArea 指定的透视区域
  12. * @returns GC.Spread.Sheets.Style 样式对象
  13. */
  14. getStyle (pivotArea: IPivotArea): Style
复制代码



0 个回复

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