iview/src/components/table/cell.vue

93 lines
3.2 KiB
Vue
Raw Normal View History

2016-11-25 15:47:28 +08:00
<template>
2017-03-09 15:24:40 +08:00
<div :class="classes" ref="cell">
2016-11-28 14:23:49 +08:00
<template v-if="renderType === 'index'">{{naturalIndex + 1}}</template>
2016-11-25 22:51:50 +08:00
<template v-if="renderType === 'selection'">
2017-03-09 14:11:22 +08:00
<Checkbox :value="checked" @on-change="toggleSelect" :disabled="disabled"></Checkbox>
2016-11-25 22:51:50 +08:00
</template>
2017-03-09 14:11:22 +08:00
<template v-if="renderType === 'normal'"><span v-html="row[column.key]"></span></template>
2017-06-02 10:35:18 +08:00
<template v-if="renderType === 'expand' && !row._disableExpand">
2017-05-27 15:13:10 +08:00
<div :class="expandCls" @click="toggleExpand">
<Icon type="ios-arrow-right"></Icon>
</div>
</template>
2017-06-09 16:44:24 +08:00
<Cell
v-if="renderType === 'render'"
:row="row"
:column="column"
:index="index"
:render="column.render"></Cell>
2016-11-25 15:47:28 +08:00
</div>
</template>
<script>
2017-06-09 16:44:24 +08:00
import Cell from './expand';
2017-05-27 15:13:10 +08:00
import Icon from '../icon/icon.vue';
2016-11-25 22:51:50 +08:00
import Checkbox from '../checkbox/checkbox.vue';
2016-11-25 15:47:28 +08:00
export default {
2017-03-09 14:11:22 +08:00
name: 'TableCell',
2017-06-09 16:44:24 +08:00
components: { Icon, Checkbox, Cell },
2016-11-25 15:47:28 +08:00
props: {
prefixCls: String,
row: Object,
column: Object,
2016-11-28 14:23:49 +08:00
naturalIndex: Number, // index of rebuildData
index: Number, // _index of data
2016-11-26 08:57:09 +08:00
checked: Boolean,
disabled: Boolean,
2017-05-27 15:13:10 +08:00
expanded: Boolean,
2016-11-30 13:17:55 +08:00
fixed: {
type: [Boolean, String],
default: false
}
2016-11-25 15:47:28 +08:00
},
data () {
return {
renderType: '',
uid: -1,
context: this.$parent.$parent.$parent.currentContext
2016-12-25 22:49:42 +08:00
};
2016-11-25 15:47:28 +08:00
},
2016-11-25 22:51:50 +08:00
computed: {
classes () {
return [
`${this.prefixCls}-cell`,
{
[`${this.prefixCls}-hidden`]: !this.fixed && this.column.fixed && (this.column.fixed === 'left' || this.column.fixed === 'right'),
2017-05-27 15:13:10 +08:00
[`${this.prefixCls}-cell-ellipsis`]: this.column.ellipsis || false,
[`${this.prefixCls}-cell-with-expand`]: this.renderType === 'expand'
2016-11-25 22:51:50 +08:00
}
2016-12-25 22:49:42 +08:00
];
2017-05-27 15:13:10 +08:00
},
expandCls () {
return [
`${this.prefixCls}-cell-expand`,
{
[`${this.prefixCls}-cell-expand-expanded`]: this.expanded
}
2017-05-27 16:19:28 +08:00
];
2016-11-25 22:51:50 +08:00
}
},
2016-11-25 15:47:28 +08:00
methods: {
2016-11-28 14:23:49 +08:00
toggleSelect () {
this.$parent.$parent.$parent.toggleSelect(this.index);
2017-05-27 15:13:10 +08:00
},
toggleExpand () {
this.$parent.$parent.$parent.toggleExpand(this.index);
2016-11-25 15:47:28 +08:00
}
},
2017-03-09 14:11:22 +08:00
created () {
2016-11-25 15:47:28 +08:00
if (this.column.type === 'index') {
this.renderType = 'index';
2016-11-25 22:51:50 +08:00
} else if (this.column.type === 'selection') {
this.renderType = 'selection';
2017-05-27 15:13:10 +08:00
} else if (this.column.type === 'expand') {
this.renderType = 'expand';
2016-11-25 15:47:28 +08:00
} else if (this.column.render) {
this.renderType = 'render';
} else {
this.renderType = 'normal';
}
}
2016-12-25 22:49:42 +08:00
};
</script>