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

Commit

Permalink
feat(api): find
Browse files Browse the repository at this point in the history
API find add type option
  • Loading branch information
Dushusir committed Dec 18, 2020
1 parent 4c012bc commit ea97233
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 15 deletions.
16 changes: 16 additions & 0 deletions docs/guide/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,20 @@ In this case, after Luckysheet is modified in real time, the changes can be seen
- Triggered before the workbook is created [workbookCreateBefore](/guide/config.html#workbookcreatebefore)
- Triggered after the workbook is created [workbookCreateAfter](/guide/config.html#workbookcreateafter)

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

## **<span style="font-size:20px;">Q</span>** When create, the first cell is selected by default, how to remove it?

**<span style="font-size:20px;">A</span>** When the cell is selected, it is highlighted by default, just remove the highlight, use API: [setRangeShow](/guide/api.html#setrangeshow-range-setting)

```js
luckysheet.setRangeShow("A2",{show:false})
```

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

## **<span style="font-size:20px;">Q</span>** Where is the right-click event bound?

**<span style="font-size:20px;">A</span>** In the source code [src/controllers/hander.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/handler.js), search for `event.which == "3"` to find the code executed by the right-click event.

------------
12 changes: 6 additions & 6 deletions docs/guide/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ Use note:
+ {Boolean} [isWholeWord]: Whether to match the whole word; the default is `false`
+ {Boolean} [isCaseSensitive]: Whether to match case sensitively; the default is `false`
+ {Number} [order]: Worksheet subscript; the default value is the current worksheet subscript
+ {String} [type]: cell attribute; the default value is `"m"`

- **Explanation**

Expand All @@ -184,6 +185,8 @@ Use note:

- Find the string `"value"` in the current worksheet
`luckysheet.find("value")`
- Find cells in the current worksheet whose formula contains `"SUM"`
`luckysheet.find("SUM",{type:"f"})`

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

Expand Down Expand Up @@ -869,7 +872,6 @@ Use note:
------------

### getRangeJson(title [,setting])


- **Parameter**

Expand All @@ -896,8 +898,7 @@ Use note:
The returned result is:
```json
[
{ "A": "value1", "B": "value3" },
{ "A": "value2", "B": "value4" }
{ "value1": "value2", "value3": "value4" }
]
```

Expand All @@ -908,7 +909,8 @@ Use note:
The returned result is:
```json
[
{ "value1": "value2", "value3": "value4" }
{ "A": "value1", "B": "value3" },
{ "A": "value2", "B": "value4" }
]
```

Expand Down Expand Up @@ -1121,8 +1123,6 @@ Use note:

### setRangeShow(range [,setting])<div id='setRangeShow'></div>

[todo]

- **Parameter**

- {Array | Object | String} [range]: The range of the selection, the format of the supported selection is `"A1:B2"`, `"sheetName!A1:B2"` or `{row:[0,1],column: [0,1]}`, allows an array of multiple selections; the default is the current selection
Expand Down
15 changes: 15 additions & 0 deletions docs/guide/operate.md
Original file line number Diff line number Diff line change
Expand Up @@ -886,3 +886,18 @@ There are four types of chart operations: add new chart -"add", move chart posit
```js
luckysheetfile[0].chart[v.chart_id] = v;
```

## Backend return format

Data format returned by websocket backend
```js
{
createTime: command sending time
data:{} modified command
id: "7a" websocket id
returnMessage: "success"
status: "0" 0 tells the front end to modify according to the data command 1 meaningless
type: 0: connection is successful, 1: send to the currently connected user, 2: send information to other users, 3: send selection location information, 999: user disconnected
username: username
}
```
16 changes: 16 additions & 0 deletions docs/zh/guide/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,20 @@ Luckysheet教程里采用的CDN链接是 [jsdelivr](https://www.jsdelivr.com/pac
- 表格创建之前触发 [workbookCreateBefore](/zh/guide/config.html#workbookcreatebefore)
- 表格创建之后触发 [workbookCreateAfter](/zh/guide/config.html#workbookcreateafter)

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

## **<span style="font-size:20px;">Q</span>** create的时候默认选中第一个单元格,怎么去除?

**<span style="font-size:20px;">A</span>** 选中单元格时默认是高亮,把高亮去除即可,使用API: [setRangeShow](/zh/guide/api.html#setrangeshow-range-setting)

```js
luckysheet.setRangeShow("A2",{show:false})
```

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

## **<span style="font-size:20px;">Q</span>** 右键事件绑定在哪?

**<span style="font-size:20px;">A</span>** 在源码的 [src/controllers/hander.js](https://github.com/mengshukeji/Luckysheet/blob/master/src/controllers/handler.js) 搜索`event.which == "3"`即可找到右键事件触发执行的代码。

------------
9 changes: 6 additions & 3 deletions docs/zh/guide/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
+ {Boolean} [isWholeWord]: 是否整词匹配;默认为 `false`
+ {Boolean} [isCaseSensitive]: 是否区分大小写匹配;默认为 `false`
+ {Number} [order]: 工作表下标;默认值为当前工作表下标
+ {String} [type]: 单元格属性;默认值为`"m"`

- **说明**

Expand All @@ -187,6 +188,8 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开

- 当前工作表查找`"value"`字符串
`luckysheet.find("value")`
- 当前工作表查找公式包含`"SUM"`的单元格
`luckysheet.find("SUM",{type:"f"})`

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

Expand Down Expand Up @@ -882,8 +885,7 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
则返回结果为:
```json
[
{ "A": "value1", "B": "value3" },
{ "A": "value2", "B": "value4" }
{ "value1": "value2", "value3": "value4" }
]
```

Expand All @@ -894,7 +896,8 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
则返回结果为:
```json
[
{ "value1": "value2", "value3": "value4" }
{ "A": "value1", "B": "value3" },
{ "A": "value2", "B": "value4" }
]
```

Expand Down
15 changes: 15 additions & 0 deletions docs/zh/guide/operate.md
Original file line number Diff line number Diff line change
Expand Up @@ -1266,3 +1266,18 @@
```js
luckysheetfile[0].chart[v.chart_id] = v;
```

## 后端返回格式

websocket 后端返回的数据格式
```js
{
createTime: 命令发送时间
data:{} 修改的命令
id: "7a" websocket的id
returnMessage: "success"
status: "0" 0告诉前端需要根据data的命令修改 1无意义
type: 0:连接成功,1:发送给当前连接的用户,2:发送信息给其他用户,3:发送选区位置信息,999:用户连接断开
username: 用户名
}
```
14 changes: 8 additions & 6 deletions src/global/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ export function setCellFormat(row, column, attr, value, options = {}) {
* @param {Boolean} options.isWholeWord 是否整词匹配;默认为 false
* @param {Boolean} options.isCaseSensitive 是否区分大小写匹配;默认为 false
* @param {Number} options.order 工作表索引;默认值为当前工作表索引
* @param {String} options.type 单元格属性;默认值为m
*/
export function find(content, options = {}) {
if (!content && content != 0) {
Expand All @@ -394,7 +395,8 @@ export function find(content, options = {}) {
isRegularExpression = false,
isWholeWord = false,
isCaseSensitive = false,
order = curSheetOrder
order = curSheetOrder,
type = "m"
} = { ...options };
let targetSheetData = Store.luckysheetfile[order].data;

Expand All @@ -416,11 +418,11 @@ export function find(content, options = {}) {

if (isWholeWord) {
if (isCaseSensitive) {
if (content.toString() == cell.m) {
if (content.toString() == cell[type]) {
result.push(cell)
}
} else {
if (cell.m && content.toString().toLowerCase() == cell.m.toLowerCase()) {
if (cell[type] && content.toString().toLowerCase() == cell[type].toLowerCase()) {
result.push(cell)
}
}
Expand All @@ -431,17 +433,17 @@ export function find(content, options = {}) {
} else {
reg = new RegExp(func_methods.getRegExpStr(content), 'ig')
}
if (reg.test(cell.m)) {
if (reg.test(cell[type])) {
result.push(cell)
}
} else if (isCaseSensitive) {
let reg = new RegExp(func_methods.getRegExpStr(content), 'g');
if (reg.test(cell.m)) {
if (reg.test(cell[type])) {
result.push(cell);
}
} else {
let reg = new RegExp(func_methods.getRegExpStr(content), 'ig');
if (reg.test(cell.m)) {
if (reg.test(cell[type])) {
result.push(cell);
}
}
Expand Down

0 comments on commit ea97233

Please sign in to comment.