Skip to content

Commit

Permalink
feat: add createEvaluator docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tinymins committed Aug 29, 2024
1 parent cfa6272 commit f16f735
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ const DRIP_TABLE_SIDEBAR = [
{ title: '自定义多选 renderSelection', link: '/drip-table/props/render-selection' },
{ title: '自定义分页器 renderPagination', link: '/drip-table/props/render-pagination' },
{ title: '自定义列头筛选器 renderHeaderCellFilter', link: '/drip-table/props/render-header-cell-filter' },
{ title: '自定义沙箱 createEvaluator', link: '/drip-table/props/create-evaluator' },
],
},
{
Expand Down
104 changes: 104 additions & 0 deletions docs/drip-table/props/create-evaluator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
title: 自定义沙箱 createEvaluator
toc: content
---

## 自定义沙箱函数创建 createEvaluator

- 描述:自定义沙箱函数创建

```jsx
/**
* transform: true
* defaultShowCode: false
* hideActions: ["CSB"]
*/
import React from "react";
import DripTable from "drip-table";

const schema = {
pagination: {
size: 'small',
pageSize: 2,
position: 'bottomCenter',
},
columns: [
{
key: "mock_1",
title: "序号",
dataIndex: "name",
component: "text",
width: "200px",
align: "center",
options: {
mode: "custom",
format:
"{{$custom}} {{props.recordIndex + 1}}",
},
},
{
key: "mock_2",
title: "商品名称",
dataIndex: "name",
component: "text",
options: {
mode: "custom",
format:
"这是一个自定义渲染,商品名称为“{{props.record.name}}”,价格为“{{props.record.price}}元”。",
},
},
],
};

const dataSource = [
{
id: 1,
name: "商品一",
price: 7999,
status: "onSale",
description:
"商品是为了出售而生产的劳动成果,是人类社会生产力发展到一定历史阶段的产物,是用于交换的劳动产品。",
},
{
id: 2,
name: "商品二",
price: 7999,
status: "onSale",
description:
"商品是为了出售而生产的劳动成果,是人类社会生产力发展到一定历史阶段的产物,是用于交换的劳动产品。",
},
{
id: 3,
name: "商品三",
price: 7999,
status: "onSale",
description:
"商品是为了出售而生产的劳动成果,是人类社会生产力发展到一定历史阶段的产物,是用于交换的劳动产品。",
},
{
id: 4,
name: "商品四",
price: 7999,
status: "onSale",
description:
"商品是为了出售而生产的劳动成果,是人类社会生产力发展到一定历史阶段的产物,是用于交换的劳动产品。",
},
];

const Demo = () => {
return (
<React.Fragment>
<DripTable
schema={schema}
dataSource={dataSource}
createEvaluator={(script, contextKeys = []) => {
script = `return function(${contextKeys.join(', ')}) { ${script} }`;
return new Function('window', '$custom', script)(window, 'CUSTOM VALUE');
}}
/>
</React.Fragment>
);
};

export default Demo;
```
1 change: 1 addition & 0 deletions docs/drip-table/props/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ toc: content
| [renderSelection](/drip-table/props/render-selection) | 自定义多选 | × | [🔗 示例](/drip-table/props/render-selection) |
| [renderPagination](/drip-table/props/render-pagination) | 自定义分页器 | × | [🔗 示例](/drip-table/props/render-pagination) |
| [renderHeaderCellFilter](/drip-table/props/render-header-cell-filter) | 自定义列头筛选器 | × | [🔗 示例](/drip-table/props/render-header-cell-filter) |
| [createEvaluator](/drip-table/props/create-evaluator) | 自定义沙箱 | × | [🔗 示例](/drip-table/props/create-evaluator) |

### 示例

Expand Down

0 comments on commit f16f735

Please sign in to comment.