Blame view

src/components/table/table-head.vue 7.06 KB
2cb8a6d9   梁灏   commit Table comp...
1
  <template>
a404bbae   梁灏   update Table #167
2
      <table cellspacing="0" cellpadding="0" border="0" :style="styles">
7f34c510   梁灏   update Table
3
          <colgroup>
3d6fa54b   梁灏   update Table
4
              <col v-for="column in columns" :width="setCellWidth(column, $index, true)">
7f34c510   梁灏   update Table
5
6
7
          </colgroup>
          <thead>
              <tr>
f9f1865c   梁灏   Table columns add...
8
                  <th v-for="(index, column) in columns" :class="alignCls(column, 'head')">
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
                              </span>
adaeca88   梁灏   update Table
17
                              <Poptip
5d0499ce   梁灏   update Table
18
                                  v-if="isPopperShow(column)"
adaeca88   梁灏   update Table
19
20
21
                                  :visible.sync="column._filterVisible"
                                  placement="bottom"
                                  @on-popper-hide="handleFilterHide($index)">
642299b9   梁灏   update Table
22
                                  <span :class="[prefixCls + '-filter']">
99f80db0   梁灏   update Table
23
                                      <i class="ivu-icon ivu-icon-funnel" :class="{on: column._isFiltered}"></i>
642299b9   梁灏   update Table
24
                                  </span>
adaeca88   梁灏   update Table
25
                                  <div slot="content" :class="[prefixCls + '-filter-list']" v-if="column._filterMultiple">
99f80db0   梁灏   update Table
26
27
28
29
30
                                      <div :class="[prefixCls + '-filter-list-item']">
                                          <checkbox-group :model.sync="column._filterChecked">
                                              <checkbox v-for="item in column.filters" :value="item.value">{{ item.label }}</checkbox>
                                          </checkbox-group>
                                      </div>
99f80db0   梁灏   update Table
31
                                      <div :class="[prefixCls + '-filter-footer']">
4ab11811   梁灏   some component su...
32
33
                                          <i-button type="text" size="small" :disabled="!column._filterChecked.length" @click="handleFilter($index)">{{ t('i.table.confirmFilter') }}</i-button>
                                          <i-button type="text" size="small" @click="handleReset($index)">{{ t('i.table.resetFilter') }}</i-button>
99f80db0   梁灏   update Table
34
                                      </div>
642299b9   梁灏   update Table
35
                                  </div>
adaeca88   梁灏   update Table
36
                                  <div slot="content" :class="[prefixCls + '-filter-list']" v-else>
d0e206c5   梁灏   Table add content...
37
                                      <ul :class="[prefixCls + '-filter-list-single']">
45e7ed7e   梁灏   update Table
38
                                          <li
89670198   梁灏   publish 0.9.9-rc-5
39
                                              :class="itemAllClasses(column)"
4ab11811   梁灏   some component su...
40
                                              @click="handleReset($index)">{{ t('i.table.clearFilter') }}</li>
45e7ed7e   梁灏   update Table
41
                                          <li
89670198   梁灏   publish 0.9.9-rc-5
42
                                              :class="itemClasses(column, item)"
45e7ed7e   梁灏   update Table
43
44
                                              v-for="item in column.filters"
                                              @click="handleSelect(index, item.value)">{{ item.label }}</li>
adaeca88   梁灏   update Table
45
46
                                      </ul>
                                  </div>
642299b9   梁灏   update Table
47
                              </Poptip>
52874e27   梁灏   update Table
48
                          </template>
7f34c510   梁灏   update Table
49
50
51
52
53
                      </div>
                  </th>
              </tr>
          </thead>
      </table>
2cb8a6d9   梁灏   commit Table comp...
54
55
  </template>
  <script>
99f80db0   梁灏   update Table
56
      import CheckboxGroup from '../checkbox/checkbox-group.vue';
0d136465   梁灏   update Table
57
      import Checkbox from '../checkbox/checkbox.vue';
642299b9   梁灏   update Table
58
      import Poptip from '../poptip/poptip.vue';
99f80db0   梁灏   update Table
59
      import iButton from '../button/button.vue';
0d136465   梁灏   update Table
60
      import Mixin from './mixin';
4ab11811   梁灏   some component su...
61
      import Locale from '../../mixins/locale';
0d136465   梁灏   update Table
62
  
2cb8a6d9   梁灏   commit Table comp...
63
      export default {
4ab11811   梁灏   some component su...
64
          mixins: [ Mixin, Locale ],
99f80db0   梁灏   update Table
65
          components: { CheckboxGroup, Checkbox, Poptip, iButton },
2cb8a6d9   梁灏   commit Table comp...
66
67
          props: {
              prefixCls: String,
7f34c510   梁灏   update Table
68
              style: Object,
0d136465   梁灏   update Table
69
              columns: Array,
d3dfdb26   梁灏   update Table
70
              objData: Object,
6c99b9fe   梁灏   update Table
71
              data: Array,    // rebuildData
224a3ae5   梁灏   publish 0.9.9-rc-3
72
              columnsWidth: Object,
5d0499ce   梁灏   update Table
73
74
75
76
              fixed: {
                  type: [Boolean, String],
                  default: false
              }
2cb8a6d9   梁灏   commit Table comp...
77
          },
2cb8a6d9   梁灏   commit Table comp...
78
          computed: {
a404bbae   梁灏   update Table #167
79
80
81
82
83
84
              styles () {
                  const style = Object.assign({}, this.style);
                  const width = this.$parent.bodyHeight === 0 ? parseInt(this.style.width) : parseInt(this.style.width) + this.$parent.scrollBarWidth;
                  style.width = `${width}px`;
                  return style;
              },
0d136465   梁灏   update Table
85
              isSelectAll () {
d3dfdb26   梁灏   update Table
86
                  let isSelectAll = true;
63e0444e   梁灏   fixed #142
87
                  if (!this.data.length) isSelectAll = false;
6c99b9fe   梁灏   update Table
88
89
90
91
92
93
  
                  for (let i = 0; i < this.data.length; i++) {
                      if (!this.objData[this.data[i]._index]._isChecked) {
                          isSelectAll = false;
                          break;
                      }
d3dfdb26   梁灏   update Table
94
95
96
                  }
  
                  return isSelectAll;
0d136465   梁灏   update Table
97
              }
2cb8a6d9   梁灏   commit Table comp...
98
99
          },
          methods: {
c6f21c2f   jingsam   :bug: fix ie bug
100
101
102
103
104
105
              cellClasses (column) {
                  return [
                      `${this.prefixCls}-cell`,
                      {
                          [`${this.prefixCls}-hidden`]: !this.fixed && column.fixed && (column.fixed === 'left' || column.fixed === 'right')
                      }
b0893113   jingsam   :art: add eslint
106
                  ];
c6f21c2f   jingsam   :bug: fix ie bug
107
              },
89670198   梁灏   publish 0.9.9-rc-5
108
109
110
111
112
113
              itemClasses (column, item) {
                  return [
                      `${this.prefixCls}-filter-select-item`,
                      {
                          [`${this.prefixCls}-filter-select-item-selected`]: column._filterChecked[0] === item.value
                      }
b0893113   jingsam   :art: add eslint
114
                  ];
89670198   梁灏   publish 0.9.9-rc-5
115
116
117
118
119
120
121
              },
              itemAllClasses (column) {
                  return [
                      `${this.prefixCls}-filter-select-item`,
                      {
                          [`${this.prefixCls}-filter-select-item-selected`]: !column._filterChecked.length
                      }
b0893113   jingsam   :art: add eslint
122
                  ];
89670198   梁灏   publish 0.9.9-rc-5
123
              },
2cb8a6d9   梁灏   commit Table comp...
124
125
126
127
128
129
              renderHeader (column, $index) {
                  if ('renderHeader' in this.columns[$index]) {
                      return this.columns[$index].renderHeader(column, $index);
                  } else {
                      return column.title || '#';
                  }
744eb0af   梁灏   update Table comp...
130
              },
0d136465   梁灏   update Table
131
132
              selectAll () {
                  const status = !this.isSelectAll;
3d9e4f20   梁灏   update Table
133
                  this.$parent.selectAll(status);
52874e27   梁灏   update Table
134
              },
35ad3764   梁灏   update Table
135
136
137
              handleSort (index, type) {
                  if (this.columns[index]._sortType === type) {
                      type = 'normal';
741b987a   梁灏   update Table
138
                  }
35ad3764   梁灏   update Table
139
                  this.$parent.handleSort(index, type);
642299b9   梁灏   update Table
140
141
              },
              handleFilter (index) {
adaeca88   梁灏   update Table
142
                  this.$parent.handleFilter(index);
99f80db0   梁灏   update Table
143
              },
45e7ed7e   梁灏   update Table
144
145
146
              handleSelect (index, value) {
                  this.$parent.handleFilterSelect(index, value);
              },
99f80db0   梁灏   update Table
147
              handleReset (index) {
adaeca88   梁灏   update Table
148
                  this.$parent.handleFilterReset(index);
99f80db0   梁灏   update Table
149
              },
adaeca88   梁灏   update Table
150
151
              handleFilterHide (index) {
                  this.$parent.handleFilterHide(index);
2cb8a6d9   梁灏   commit Table comp...
152
153
              }
          }
b0893113   jingsam   :art: add eslint
154
155
      };
  </script>