Files
smart-table/README.md

93 lines
3.4 KiB
Markdown
Raw Normal View History

2020-01-30 13:24:36 +08:00
# Smart Table 组件
2020-01-13 16:57:45 +08:00
**专处理纯静态table固定头列及排序功能**
2020-01-13 16:55:59 +08:00
此组件库常用于服务端处理数据后直接返回HTML渲染在客户端需要表格的多样化功能。
-- 初衷 --
2020-01-13 16:57:45 +08:00
方便在服务端直接返回已经渲染好的table数据后增加table的组件功能如头固定、左右列固定、排序功能
此项目不依赖任何其他库
2020-01-13 16:55:59 +08:00
-- 设计 --
2020-01-13 16:57:45 +08:00
组件内核借鉴虚拟Dom实现元素排序移动借鉴React的Diff算法实现保证元素的可重复使用。增加debounce及throttle保证体验。
2020-01-13 16:55:59 +08:00
-- 优势 --
2020-01-13 16:57:45 +08:00
2020-01-13 16:55:59 +08:00
- 支持多元化头部
- 轻量,使用方便
- 性能高
## 体验
2020-01-30 13:24:36 +08:00
可直接访问https://peng92055.github.io/smart-table
2020-01-13 16:25:20 +08:00
2020-01-30 13:24:36 +08:00
## Usage
- 加载UI库
```html
2020-01-29 14:06:51 +08:00
<script type="text/javascript" src="./dist/smartTable.[chunkhash].js"></script>
2020-01-29 14:39:11 +08:00
或者使用七牛云空间的存储
<script type="text/javascript" src="http://q4uv9bkgj.bkt.clouddn.com/smartTable.26faa588.js"></script>
2020-01-13 16:55:59 +08:00
```
2020-01-30 13:24:36 +08:00
- 输出静态HTML 表格基础属性需在服务端返回前指定<br>
**规则1、必须指定class为smart-table2、th或td中必须有一层class为cell的div包裹后期迭代自动处理掉**
2020-01-30 13:24:36 +08:00
```html
<div class="smart-table" id="smartTable">
<table stripe>
<thead>
<tr>
<th fixed sort>
<div class="cell">Id</div>
</th>
...
<tbody>
<tr>
<td>
<div class="cell">DD001</div>
</th>
...
<tr unsort>
<td>
<div class="cell">合计</div>
</th>
2020-01-13 16:25:20 +08:00
```
2020-01-30 13:24:36 +08:00
- 初始化表格
```javascript
2020-01-29 13:04:18 +08:00
new SmartTable({
2020-01-30 13:24:36 +08:00
selector: '#smartTable',
2020-01-29 13:04:18 +08:00
tableHeight: 300,
textAlign: 'left',
size: 'middle'
2020-01-28 14:20:55 +08:00
})
2020-01-13 16:55:59 +08:00
```
2020-01-30 13:24:36 +08:00
### Table Attributes
2020-01-30 13:24:36 +08:00
| Property | Tag Position | Description |
| :---------------- | :--------------------- | :---------------------------------------------------------------- |
| stripe | table | 表格是否需要斑马间隔色 |
| fixed | thead -> tr -> th | 是否固定该列 |
| sort | thead -> tr -> th | 是否对该列有排序功能默认按照string排序可指定为sort="number" |
| unsort | tbody -> tr | 可指定body中的某一行不参与排序 |
### Table Options
2020-01-30 13:24:36 +08:00
| Property | Type | Required | Description | Default |
| :---------------------| :----------------- | :---------- | :------------------------------------------ | :------------ |
| selector | string | yes | 需要初始化的表格元素 | |
| tableHeight | number or function | no | 可指定表格的高度 | |
| textAlign | string | no | 表格文本的水平排列方式(left、center、right) | center |
| size | string | no | 每一行的垂直高度风格(large、middle、small) | small |
## 启动项目
```
npm run serve
```
## build 流程
```
npm run build
2020-01-13 16:55:59 +08:00
```