iview/src/components/table/table-head.vue

64 lines
2.2 KiB
Vue
Raw Normal View History

<template>
2016-11-26 08:57:09 +08:00
<table cellspacing="0" cellpadding="0" border="0" :style="style">
<colgroup>
<col v-for="column in columns" :width="setCellWidth(column, $index)">
</colgroup>
<thead>
<tr>
<th v-for="column in columns" :class="alignCls(column)">
<div :class="[prefixCls + '-cell', {[prefixCls + '-hidden']: !fixed && column.fixed && (column.fixed === 'left' || column.fixed === 'right')}]">
<template v-if="column.type === 'selection'"><Checkbox :checked="isSelectAll" @on-change="selectAll"></Checkbox></template>
<template v-else>{{{ renderHeader(column, $index) }}}</template>
</div>
</th>
</tr>
</thead>
</table>
</template>
<script>
2016-11-24 15:27:46 +08:00
import Checkbox from '../checkbox/checkbox.vue';
import Mixin from './mixin';
import { deepCopy } from '../../utils/assist';
export default {
2016-11-24 15:27:46 +08:00
mixins: [ Mixin ],
components: { Checkbox },
props: {
prefixCls: String,
2016-11-26 08:57:09 +08:00
style: Object,
2016-11-24 15:27:46 +08:00
columns: Array,
2016-11-26 08:57:09 +08:00
cloneData: Array,
fixed: Boolean
},
computed: {
2016-11-24 15:27:46 +08:00
isSelectAll () {
return !this.cloneData.some(data => !data._isChecked);
}
},
methods: {
2016-11-26 08:57:09 +08:00
setCellWidth (column, index) {
return this.$parent.setCellWidth(column, index);
},
renderHeader (column, $index) {
if ('renderHeader' in this.columns[$index]) {
return this.columns[$index].renderHeader(column, $index);
} else {
return column.title || '#';
}
},
2016-11-24 15:27:46 +08:00
selectAll () {
const status = !this.isSelectAll;
let tmpData = deepCopy(this.cloneData);
tmpData.forEach((data) => {
data._isChecked = status;
});
this.cloneData = tmpData;
if (status) {
this.$parent.selectAll();
}
}
}
}
</script>