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

Commit

Permalink
fix(hook function): cellupdate
Browse files Browse the repository at this point in the history
1.Hook function cellUpdate change to cellUpdateBefore 2.Add hook function cellUpdated
  • Loading branch information
mengshukeji committed Nov 24, 2020
1 parent 5863b3f commit 5e8f71f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 33 deletions.
44 changes: 20 additions & 24 deletions docs/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,48 +536,44 @@ The hook functions are uniformly configured under ʻoptions.hook`, and configura
- {Object} [v]: Cell object

------------
### cellEditBefore
(TODO)
- Type: Function
- Default: null
- Usage: Triggered after double-clicking the cell, that is, when double-clicking the cell to edit the content, this method is triggered first
- Parameter:
### cellUpdateBefore

- TypeFunction
- Defaultnull
- UsageTriggered before updating this cell
- Parameter
- {Number} [r]: Row number of cell
- {Number} [c]: Column number of cell
- {Object} [v]: Cell object
- {Object | String | Number} [value]: Cell content to be modified
- {Boolean} [isRefresh]: Whether to refresh the entire table

------------
### cellExitEditBefore
(TODO)
- Type: Function
- Default: null
- Usage: Exit the cell editing state, which is triggered before saving the cell value
- Parameter:
### cellUpdated

- TypeFunction
- Defaultnull
- Usage:Triggered after updating this cell
- Parameter
- {Number} [r]: Row number of cell
- {Number} [c]: Column number of cell
- {Object} [oldV]: Cell object before Modified
- {Object} [newV]: Cell object after Modified
- {Object} [oldValue]: Cell object before modification
- {Object} [newValue]: Cell object after modification
- {Boolean} [isRefresh]: Whether to refresh the entire table

------------

## Selected area

### rangeSelectBefore
- Type: Function
- Default: null
- Usage: Frame selection or trigger before setting selection
- Parameter:
- {Object | Array} [range]: Selection area, may be multiple selection areas

------------
### rangeSelectAfter
### rangeSelect
- Type: Function
- Default: null
- Usage: Frame selection or trigger after setting selection
- Parameter:
- {Object} [sheet]: Current sheet object
- {Object | Array} [range]: Selection area, may be multiple selection areas

------------

### rangeMoveBefore
- Type: Function
- Default: null
Expand Down
18 changes: 16 additions & 2 deletions docs/zh/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,17 +655,30 @@ Luckysheet开放了更细致的自定义配置选项,分别有
- {Object} [sheet]:当前sheet对象
- {Object} [ctx]: 当前画布的context
------------
### cellUpdate
### cellUpdateBefore

- 类型:Function
- 默认值:null
- 作用:更新这个单元格时触发,在退出编辑保存单元格值前触发
- 作用:更新这个单元格之前触发,`return false` 则不执行后续的更新
- 参数:
- {Number} [r]: 单元格所在行数
- {Number} [c]: 单元格所在列数
- {Object | String | Number} [value]: 要修改的单元格内容
- {Boolean} [isRefresh]: 是否刷新整个表格

------------
### cellUpdated

- 类型:Function
- 默认值:null
- 作用:更新这个单元格后触发
- 参数:
- {Number} [r]: 单元格所在行数
- {Number} [c]: 单元格所在列数
- {Object} [oldValue]: 修改前的单元格对象
- {Object} [newValue]: 修改后的单元格对象
- {Boolean} [isRefresh]: 是否刷新整个表格

------------
### rowTitleCellRenderBefore

Expand Down Expand Up @@ -852,6 +865,7 @@ Luckysheet开放了更细致的自定义配置选项,分别有
- 默认值:null
- 作用:框选或者设置选区后触发
- 参数:
- {Object} [sheet]:当前sheet对象
- {Object | Array} [range]: 选区范围,可能为多个选区

------------
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function selectHightlightShow(isRestore=false) {
const luckysheet_select_save_previous = JSON.stringify(Store.luckysheet_select_save);

if(Store.luckysheet_select_save_previous == null || Store.luckysheet_select_save_previous !== luckysheet_select_save_previous){
method.createHookFunction('rangeSelect', Store.currentSheetIndex, Store.luckysheet_select_save);
method.createHookFunction('rangeSelect', Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)], Store.luckysheet_select_save);
}

Store.luckysheet_select_save_previous = luckysheet_select_save_previous;
Expand Down
17 changes: 15 additions & 2 deletions src/global/formula.js
Original file line number Diff line number Diff line change
Expand Up @@ -1229,13 +1229,12 @@ const luckysheetformula = {
});
},
updatecell: function(r, c, value, isRefresh=true) {
// 钩子函数
method.createHookFunction('cellUpdate',r,c,value,isRefresh);

let _this = this;

let $input = $("#luckysheet-rich-text-editor");
let inputText = $input.text(), inputHtml = $input.html();


if (_this.rangetosheet != null && _this.rangetosheet != Store.currentSheetIndex) {
sheetmanage.changeSheetExec(_this.rangetosheet);
Expand All @@ -1258,6 +1257,10 @@ const luckysheetformula = {
}

let curv = Store.flowdata[r][c];

// Store old value for hook function
const oldValue = JSON.stringify(curv);

let isPrevInline = isInlineStringCell(curv);
let isCurInline = (inputText.slice(0, 1) != "=" && inputHtml.substr(0,5) == "<span");
if(!value && !isCurInline && isPrevInline){
Expand Down Expand Up @@ -1286,6 +1289,11 @@ const luckysheetformula = {
// API, we get value from user
value = value || $input.text();

// Hook function
if(!method.createHookFunction("cellUpdateBefore", r, c, value, isRefresh)){
return;
}

if(!isCurInline){
if(isRealNull(value) && !isPrevInline){
if(curv == null || (isRealNull(curv.v) && curv.spl == null && curv.f == null)){
Expand Down Expand Up @@ -1610,6 +1618,11 @@ const luckysheetformula = {
}
}

setTimeout(() => {
// Hook function
method.createHookFunction("cellUpdated", r, c, JSON.parse(oldValue), Store.flowdata[r][c], isRefresh);
}, 0);

if(isRefresh){
jfrefreshgrid(d, [{ "row": [r, r], "column": [c, c] }], allParam, isRunExecFunction);
// Store.luckysheetCellUpdate.length = 0; //clear array
Expand Down
11 changes: 7 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,17 @@
updated:function(operate){
// console.info(operate)
},
cellUpdate:function(r,c,value,isRefresh){
// console.info(r,c,value)
cellUpdateBefore:function(r,c,value,isRefresh){
// console.info('cellUpdateBefore',r,c,value,isRefresh)
},
cellUpdated:function(r,c,oldValue, newValue, isRefresh){
// console.info('cellUpdated',r,c,oldValue, newValue, isRefresh)
},
sheetActivate:function(index, isPivotInitial, isNewSheet){
// console.info(index, isPivotInitial, isNewSheet)
},
rangeSelect:function(index, range){
// console.info(index, range)
rangeSelect:function(index, sheet){
console.info(index, sheet)
}


Expand Down

0 comments on commit 5e8f71f

Please sign in to comment.