Files
smart-table/README.md

96 lines
3.6 KiB
Markdown
Raw Normal View History

2020-01-30 13:24:36 +08:00
# Smart Table 组件
2020-02-01 15:21:36 +08:00
![Badge](https://img.shields.io/badge/Hey!-Everybody-yellow)
![Version](https://img.shields.io/github/package-json/v/peng92055/smart-table)
![License](https://img.shields.io/github/license/peng92055/smart-table)
2020-01-13 16:57:45 +08:00
**专处理纯静态table固定头列及排序功能**
2020-02-02 13:21:03 +08:00
此组件库常用于服务端处理数据后直接返回HTML渲染在客户端需要表格的多样化交互功能。
2020-01-13 16:55:59 +08:00
-- 初衷 --
2020-01-13 16:57:45 +08:00
2020-02-02 13:21:03 +08:00
在不依赖任何其他库服务端已返回table完整数据后增加table客户端的组件交互功能如头列固定、排序、斑马纹等
2020-01-13 16:55:59 +08:00
-- 设计 --
2020-02-02 13:21:03 +08:00
组件内核借鉴虚拟Dom实现元素排序移动借鉴React的Diff算法实现。
2020-01-13 16:57:45 +08:00
2020-02-02 13:21:03 +08:00
-- 特点 --
2020-01-13 16:57:45 +08:00
2020-01-13 16:55:59 +08:00
- 支持多元化头部
2020-02-02 13:21:03 +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
2020-01-31 17:12:19 +08:00
- 加载UI库<br>
2020-01-31 19:39:40 +08:00
Download the minified library [smartTable.min.js](https://peng92055.github.io/smart-table/smartTable.min.js), and include it in your webpage.
2020-01-30 13:24:36 +08:00
```html
2020-01-31 17:12:19 +08:00
/* smartTable library */
<script type="text/javascript" src="js/smartTable.min.js"></script>
2020-01-13 16:55:59 +08:00
```
2020-02-02 13:21:03 +08:00
- 静态HTML(指定表格基础属性)<br>
2020-01-30 13:24:36 +08:00
```html
2020-01-31 17:12:19 +08:00
<div id="smartTable">
2020-01-30 13:24:36 +08:00
<table stripe>
<thead>
<tr>
2020-01-31 17:12:19 +08:00
<th fixed sort>Id</th>
<th colspan="1" rowspan="2" width="200">日期</th>
2020-01-30 13:24:36 +08:00
...
2020-01-31 17:12:19 +08:00
<th fixed>价格</th> <!-- 右边固定列 -->
2020-01-30 13:24:36 +08:00
<tbody>
<tr>
2020-01-31 17:12:19 +08:00
<td>DD001</td>
<td>2020-01-31</td>
2020-01-30 13:24:36 +08:00
...
2020-01-31 17:12:19 +08:00
<td>889.00</td>
2020-01-30 13:24:36 +08:00
<tr unsort>
2020-01-31 17:12:19 +08:00
<td colspan="2">合计</td>
...
<td>18988.00</td>
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-02-04 11:59:05 +08:00
hoverBgColor: '#C5DFFF',
2020-02-03 11:31:15 +08:00
height: 300,
align: 'left',
2020-01-29 13:04:18 +08:00
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 | 需要初始化的表格元素 | |
2020-02-03 11:33:35 +08:00
| height | number or function | no | 可指定表格的高度 | |
| align | string | no | 表格文本的水平排列方式(left、center、right) | center |
| size | string | no | 每一行的垂直高度风格(large、middle、small) | small |
2020-02-04 11:59:05 +08:00
| hoverBgColor | string | no | body中每行hover时的背景色 | '#EFF8FF' |
2020-01-30 13:24:36 +08:00
2020-01-31 17:12:19 +08:00
## 本地开发
### 启动项目
2020-01-30 13:24:36 +08:00
```
npm run serve
```
2020-01-31 17:12:19 +08:00
### build 流程
2020-01-30 13:24:36 +08:00
```
npm run build
2020-01-13 16:55:59 +08:00
```