Blame view

src/components/table/table-head.vue 2.96 KB
2cb8a6d9   梁灏   commit Table comp...
1
  <template>
7f34c510   梁灏   update Table
2
3
4
5
6
7
8
      <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)">
c6f21c2f   jingsam   :bug: fix ie bug
9
                      <div :class="cellClasses(column)">
7f34c510   梁灏   update Table
10
                          <template v-if="column.type === 'selection'"><Checkbox :checked="isSelectAll" @on-change="selectAll"></Checkbox></template>
52874e27   梁灏   update Table
11
12
13
                          <template v-else>
                              {{{ renderHeader(column, $index) }}}
                              <span :class="[prefixCls + '-sort']" v-if="column.sortable">
35ad3764   梁灏   update Table
14
15
                                  <i class="ivu-icon ivu-icon-arrow-up-b" :class="{on: column._sortType === 'asc'}" @click="handleSort($index, 'asc')"></i>
                                  <i class="ivu-icon ivu-icon-arrow-down-b" :class="{on: column._sortType === 'desc'}" @click="handleSort($index, 'desc')"></i>
52874e27   梁灏   update Table
16
17
                              </span>
                          </template>
7f34c510   梁灏   update Table
18
19
20
21
22
                      </div>
                  </th>
              </tr>
          </thead>
      </table>
2cb8a6d9   梁灏   commit Table comp...
23
24
  </template>
  <script>
0d136465   梁灏   update Table
25
26
27
28
      import Checkbox from '../checkbox/checkbox.vue';
      import Mixin from './mixin';
      import { deepCopy } from '../../utils/assist';
  
2cb8a6d9   梁灏   commit Table comp...
29
      export default {
0d136465   梁灏   update Table
30
31
          mixins: [ Mixin ],
          components: { Checkbox },
2cb8a6d9   梁灏   commit Table comp...
32
33
          props: {
              prefixCls: String,
7f34c510   梁灏   update Table
34
              style: Object,
0d136465   梁灏   update Table
35
              columns: Array,
d3dfdb26   梁灏   update Table
36
              objData: Object,
7f34c510   梁灏   update Table
37
              fixed: Boolean
2cb8a6d9   梁灏   commit Table comp...
38
          },
2cb8a6d9   梁灏   commit Table comp...
39
          computed: {
0d136465   梁灏   update Table
40
              isSelectAll () {
d3dfdb26   梁灏   update Table
41
42
43
44
45
46
                  let isSelectAll = true;
                  for (let i in this.objData) {
                      if (!this.objData[i]._isChecked) isSelectAll = false;
                  }
  
                  return isSelectAll;
0d136465   梁灏   update Table
47
              }
2cb8a6d9   梁灏   commit Table comp...
48
49
          },
          methods: {
c6f21c2f   jingsam   :bug: fix ie bug
50
51
52
53
54
55
56
57
              cellClasses (column) {
                  return [
                      `${this.prefixCls}-cell`,
                      {
                          [`${this.prefixCls}-hidden`]: !this.fixed && column.fixed && (column.fixed === 'left' || column.fixed === 'right')
                      }
                  ]
              },
7f34c510   梁灏   update Table
58
59
60
              setCellWidth (column, index) {
                  return this.$parent.setCellWidth(column, index);
              },
2cb8a6d9   梁灏   commit Table comp...
61
62
63
64
65
66
              renderHeader (column, $index) {
                  if ('renderHeader' in this.columns[$index]) {
                      return this.columns[$index].renderHeader(column, $index);
                  } else {
                      return column.title || '#';
                  }
744eb0af   梁灏   update Table comp...
67
              },
0d136465   梁灏   update Table
68
69
              selectAll () {
                  const status = !this.isSelectAll;
3d9e4f20   梁灏   update Table
70
                  this.$parent.selectAll(status);
52874e27   梁灏   update Table
71
              },
35ad3764   梁灏   update Table
72
73
74
              handleSort (index, type) {
                  if (this.columns[index]._sortType === type) {
                      type = 'normal';
741b987a   梁灏   update Table
75
                  }
35ad3764   梁灏   update Table
76
                  this.$parent.handleSort(index, type);
2cb8a6d9   梁灏   commit Table comp...
77
78
79
              }
          }
      }
c6f21c2f   jingsam   :bug: fix ie bug
80
  </script>