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

59 lines
1.8 KiB
Vue
Raw Normal View History

<template>
<thead>
<tr>
2016-11-24 15:27:46 +08:00
<th v-for="column in columns" :class="alignCls(column)">
2016-11-25 22:51:50 +08:00
<div :class="[prefixCls + '-cell', {[prefixCls + '-hidden']: column.fixed && (column.fixed === 'left' || column.fixed === 'right')}]">
2016-11-24 15:27:46 +08:00
<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>
</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-24 15:27:46 +08:00
columns: Array,
cloneData: Array
},
data () {
return {
}
},
computed: {
2016-11-24 15:27:46 +08:00
isSelectAll () {
return !this.cloneData.some(data => !data._isChecked);
}
},
methods: {
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>