1
1
# Egrid
2
2
3
- 基于 ` Element-UI ` ` Table ` 组件封装的高阶表格组件。
3
+ 基于 ` Element-UI ` ` Table ` 组件封装的高阶表格组件,可无缝支持 element 的 table 组件 。
4
4
5
- min 大小仅 4kb 。实现比较简单,源码在这: [ https://github.com/kinglisky/egrid ] ( https://github.com/kinglisky/egrid )
5
+ min 文件仅 3.8 kb 。实现比较简单,源码在这: [ https://github.com/kinglisky/egrid ] ( https://github.com/kinglisky/egrid )
6
6
7
7
首先组件依赖 ` Element Table ` ,先要安装 Element:
8
8
@@ -22,6 +22,7 @@ import Vue from 'vue'
22
22
import Egrid from ' egrid'
23
23
24
24
// table 的样式需要手动引入
25
+ import ' element-ui/lib/theme-default/icon.css'
25
26
import ' element-ui/lib/theme-default/table.css'
26
27
import ' element-ui/lib/theme-default/table-column.css'
27
28
@@ -33,7 +34,7 @@ Vue.use(Egrid)
33
34
src="//jsfiddle.net/nlush/yr0uf0fm/7/embedded/result,html,js,css/" allowfullscreen="allowfullscreen" frameborder="0">
34
35
</iframe >
35
36
36
- 表格中自定义渲染的组件 :
37
+ 先创建表格中使用的自定义组件 :
37
38
38
39
` cell-btn.vue `
39
40
``` html
@@ -105,7 +106,7 @@ export default {
105
106
return {
106
107
data: Data .data ,
107
108
columns: Data .columns ,
108
- // columnsProps 用于定义 columns 公共的属性,
109
+ // columnsProps 用于定义 columns 公共的属性
109
110
columnsProps: {
110
111
width: 120 ,
111
112
sortable: true ,
@@ -117,7 +118,7 @@ export default {
117
118
columnsSchema: {
118
119
' 地址' : {
119
120
width: ' auto' ,
120
- // propsHandler 可用于转换传给自定义组件的 props
121
+ // propsHandler 可用于转换传给自定义组件的 props 这里将 props 变成了 address
121
122
propsHandler ({ col, row }) {
122
123
return { address: row[col .prop ] }
123
124
},
@@ -162,7 +163,7 @@ export default {
162
163
163
164
# Attributes
164
165
165
- !> ` egrid ` 只是在 ` Element Table ` 封装了一层,原本设置在 ` Table ` 上的 ` props ` 与事件监听可直接设置到 ` egrid ` 上,如:` height ` ` max-height ` ` border ` ` @selection-change ` ......可参考 [ Element Tabel 文档] ( http://element.eleme.io/#/zh-CN/component/table#table-attributes )
166
+ !> ` egrid ` 只是在 ` Element Table ` 封装了一层,原本设置在 ` Table ` 上的 ` props ` 与事件监听可直接设置到 ` egrid ` 上,如:` height ` ` max-height ` ` border ` ` @selection-change ` ......具体配置可参考 [ Element Tabel 文档] ( http://element.eleme.io/#/zh-CN/component/table#table-attributes )
166
167
167
168
| 属性 | 说明 | 可选项 | 默认 |
168
169
| --- | ---- | --- | --- |
@@ -222,7 +223,7 @@ const columns = [
222
223
` listeners `
223
224
用于监听 ` component ` 配置的自定义渲染组件内部 ` $emit ` 出的事件,这里使用 Vue 2.4 引入 ` v-on ` [ 新语法] ( https://cn.vuejs.org/v2/api/#v-on ) ,可直接为 ` v-on ` 绑定一个对象,如:
224
225
``` javascrip
225
- { 'custom-event': function (data) {...} }
226
+ v-on=" { 'custom-event': function (data) {...} }"
226
227
```
227
228
228
229
` propsHandler `
@@ -236,11 +237,9 @@ const columns = [
236
237
可通过 ` propsHandler ` 对 ` { row, col, column } ` 进行转化你想要的形式:
237
238
238
239
``` javascript
239
- propsHandler ({
240
- row, col, column
241
- })
240
+ propsHandler ({ row, col, column })
242
241
243
- 转化成 =>
242
+ // 转化成 =>
244
243
245
244
{
246
245
msg: row[col .prop ],
@@ -252,7 +251,7 @@ propsHandler({
252
251
```
253
252
> columns-props 配置
254
253
255
- ` columns-props ` 配置用于定义 ` columns ` 各列默认的 props 属性。如所有的列默认都居左对齐, 不支持排序,我们可以将 columns-props 设置成:
254
+ ` columns-props ` 配置用于定义 ` columns ` 各列默认的 props 属性。如所有的列默认都 ** 居左对齐 ** , ** 不支持排序** ,我们可以将 columns-props 设置成:
256
255
257
256
``` javascript
258
257
{
@@ -278,7 +277,7 @@ propsHandler({
278
277
279
278
```
280
279
281
- ` columns-schema ` 是通过 columns 每列的 ` label ` 属性值来匹配的。这里的配置属性会覆盖 ` columns-props ` 与 ` columns ` 设置对应的列的属性值 。
280
+ ` columns-schema ` 是通过 columns 每列的 ` label ` 属性值来匹配的。这里的配置属性会覆盖 ` columns-props ` 与 ` columns ` 设置的对应的列的属性值 。
282
281
283
282
!> 覆盖的优先级为 ` columns-schema ` > ` columns ` > ` columns-props `
284
283
@@ -308,31 +307,35 @@ columnsHandler (cols) {
308
307
309
308
* ` expand ` : 表格支持折叠展开行
310
309
311
- 当 ` column-type ` 为 ` expand ` 时表格支持折叠展开行,此时可用通过 ` slot(slot="expand") ` 方式自定渲染折叠详情。
310
+ 当 ` column-type ` 为 ` expand ` 时表格支持折叠展开行,此时可用通过 ` slot (slot="expand") ` 方式自定渲染折叠详情。
312
311
313
- 当 ` column-type ` 为数组时可设置多个特殊列,` ['expand', 'index', 'selection'] ` 。
312
+ 当 ` column-type ` 为数组时可设置多个特殊列,` ['expand', 'index', 'selection'] ` ,一般很少这样使用 。
314
313
315
314
使用可参考下面的栗子🌰 :
316
315
317
316
<iframe width="100%" height="600"
318
- src="//jsfiddle.net/nlush/azr14zfs/3/embedded/result,html,js,css/" allowfullscreen="allowfullscreen" frameborder="0">
317
+ src="//jsfiddle.net/nlush/azr14zfs/3/embedded/result,html,js,css/"
318
+ allowfullscreen="allowfullscreen" frameborder="0">
319
319
</iframe >
320
320
321
321
> ` column-key-map ` 配置
322
322
323
323
考虑到 ` columns ` 中的 ` label ` 项与 ` prop ` 项对应的属性 key 不一定是 ` label ` 与 ` prop ` ,这时可以通过 ` column-key-map ` 做个映射。
324
324
325
+
326
+
325
327
# Methods
326
328
327
329
` clearSelection ` ` toggleRowSelection ` ` setCurrentRow `
328
330
329
331
!> 直接代理一层原 ` Element Table ` 的方法。可参考[ 文档] ( http://element.eleme.io/#/zh-CN/component/table#table-methods )
330
332
333
+
331
334
# Slots
332
335
333
- ` append ` :对应 ` Element Table ` 的 ` slot="append" ` , [ 文档 ] ( http://element.eleme.io/#/zh-CN/component/table#table-slot )
336
+ ` append ` :对应 ` Element Table ` 的 ` slot="append" ` [ 可参考文档 ] ( http://element.eleme.io/#/zh-CN/component/table#table-slot ) ,使用时注意设置 ` slot-append ` 为 ` true `
334
337
335
- ` expand ` : 当 ` column-type ` 为 ` expand ` 时自定义,行折叠内容的 。
338
+ ` expand ` : 当 ` column-type ` 为 ` expand ` 时使用,用于自定义折叠展开内容 。
336
339
337
340
338
341
0 commit comments