Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
fix(pivottable): fix
Browse files Browse the repository at this point in the history
1.fix pivotTable filter bug 2.cellRenderAfter example

fix #439 fix #447
  • Loading branch information
Dushusir committed Jan 11, 2021
1 parent 31bb399 commit 7cecb12
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 2 deletions.
68 changes: 68 additions & 0 deletions docs/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,74 @@ The hook functions are uniformly configured under ʻoptions.hook`, and configura
- {Object} [sheet]: Current worksheet object
- {Object} [ctx]: The context of the current canvas

- Example:

A case of drawing two pictures in the upper left corner and lower right corner of cell D1
:::::: details
```js
luckysheet.create({
hook: {
cellRenderAfter: function (cell, postion, sheetFile, ctx) {
var r = postion.r;
var c = postion.c;
if (r === 0 && c === 3) { // Specify to process cell D1
if (!window.storeUserImage) {
window.storeUserImage = {}
}

if (!window.storeUserImage[r + '_' + c]) {
window.storeUserImage[r + '_' + c] = {}
}

var img = null;
var imgRight = null;

if (window.storeUserImage[r + '_' + c].image && window.storeUserImage[r + '_' + c].imgRight) {

// Fetch directly after loading
img = window.storeUserImage[r + '_' + c].image;
imgRight = window.storeUserImage[r + '_' + c].imgRight;

} else {

img = new Image();
imgRight = new Image();

img.src = 'https://www.dogedoge.com/favicon/developer.mozilla.org.ico';
imgRight.src = 'https://www.dogedoge.com/static/icons/twemoji/svg/1f637.svg';

// The picture is cached in the memory, fetched directly next time, no need to reload
window.storeUserImage[r + '_' + c].image = img;
window.storeUserImage[r + '_' + c].imgRight = imgRight;

}


if (img.complete) { //Direct rendering that has been loaded
ctx.drawImage(img, postion.start_c, postion.start_r, 10, 10);
} else {
img.onload = function () {
ctx.drawImage(img, postion.start_c, postion.start_r, 10, 10);
}

}

if (imgRight.complete) {
ctx.drawImage(imgRight, postion.end_c - 10, postion.end_r - 10, 10, 10);
} else {

imgRight.onload = function () {
ctx.drawImage(imgRight, postion.end_c - 10, postion.end_r - 10, 10, 10);
}
}

}
}
}
})
```
:::

------------
### cellAllRenderBefore

Expand Down
68 changes: 68 additions & 0 deletions docs/zh/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,74 @@ Luckysheet开放了更细致的自定义配置选项,分别有
- {Object} [sheet]:当前sheet对象
- {Object} [ctx]: 当前画布的context

- 示例:

一个在D1单元格的左上角和右下角分别绘制两张图的案例
:::::: details
```js
luckysheet.create({
hook: {
cellRenderAfter: function (cell, postion, sheetFile, ctx) {
var r = postion.r;
var c = postion.c;
if (r === 0 && c === 3) { // 指定处理D1单元格
if (!window.storeUserImage) {
window.storeUserImage = {}
}

if (!window.storeUserImage[r + '_' + c]) {
window.storeUserImage[r + '_' + c] = {}
}

var img = null;
var imgRight = null;

if (window.storeUserImage[r + '_' + c].image && window.storeUserImage[r + '_' + c].imgRight) {

// 加载过直接取
img = window.storeUserImage[r + '_' + c].image;
imgRight = window.storeUserImage[r + '_' + c].imgRight;

} else {

img = new Image();
imgRight = new Image();

img.src = 'https://www.dogedoge.com/favicon/developer.mozilla.org.ico';
imgRight.src = 'https://www.dogedoge.com/static/icons/twemoji/svg/1f637.svg';

// 图片缓存到内存,下次直接取,不用再重新加载
window.storeUserImage[r + '_' + c].image = img;
window.storeUserImage[r + '_' + c].imgRight = imgRight;

}


if (img.complete) { // 已经加载完成的直接渲染
ctx.drawImage(img, postion.start_c, postion.start_r, 10, 10);
} else {
img.onload = function () {
ctx.drawImage(img, postion.start_c, postion.start_r, 10, 10);
}

}

if (imgRight.complete) {
ctx.drawImage(imgRight, postion.end_c - 10, postion.end_r - 10, 10, 10);
} else {

imgRight.onload = function () {
ctx.drawImage(imgRight, postion.end_c - 10, postion.end_r - 10, 10, 10);
}
}

}
}
}
})
```
:::

------------
### cellAllRenderBefore

Expand Down
5 changes: 3 additions & 2 deletions src/controllers/pivotTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ const pivotTable = {
let rowhidden = {};
if (_this.filterparm != null) {
for (let f in _this.filterparm) {
// 目的是取出rowhidden
for (let h in _this.filterparm[f]) {
if (h.rowhidden != null) {
rowhidden = $.extend(true, rowhidden, h.rowhidden);
if (h === 'rowhidden' && _this.filterparm[f][h] != null) {
rowhidden = $.extend(true, rowhidden, _this.filterparm[f][h]);
}
}
}
Expand Down

0 comments on commit 7cecb12

Please sign in to comment.