Blame view

src/components/table/table-head.vue 10.3 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>
eec3859c   huanghong   fixed table scollbar
4
5
              <col v-for="(column, index) in columns" :width="setCellWidth(column)">
              <col v-if="$parent.showVerticalScrollBar" :width="$parent.scrollBarWidth"/>
7f34c510   梁灏   update Table
6
7
          </colgroup>
          <thead>
1acabf79   梁灏   Table support mul...
8
9
10
11
12
13
              <tr v-for="(cols, rowIndex) in headRows">
                  <th
                      v-for="(column, index) in cols"
                      :colspan="column.colSpan"
                      :rowspan="column.rowSpan"
                      :class="alignCls(column)">
c6f21c2f   jingsam   :bug: fix ie bug
14
                      <div :class="cellClasses(column)">
8a392d25   梁灏   Table expand supp...
15
16
17
18
                          <template v-if="column.type === 'expand'">
                              <span v-if="!column.renderHeader">{{ column.title || '' }}</span>
                              <render-header v-else :render="column.renderHeader" :column="column" :index="index"></render-header>
                          </template>
bb49347b   梁灏   fixed #2823
19
                          <template v-else-if="column.type === 'selection'"><Checkbox :value="isSelectAll" :disabled="!data.length" @on-change="selectAll"></Checkbox></template>
52874e27   梁灏   update Table
20
                          <template v-else>
a0f48947   梁灏   Optimize Table ch...
21
                              <span v-if="!column.renderHeader" :class="{[prefixCls + '-cell-sort']: column.sortable}" @click="handleSortByHead(getColumn(rowIndex, index)._index)">{{ column.title || '#' }}</span>
096f2bfe   梁灏   fixed #1357
22
                              <render-header v-else :render="column.renderHeader" :column="column" :index="index"></render-header>
52874e27   梁灏   update Table
23
                              <span :class="[prefixCls + '-sort']" v-if="column.sortable">
9ea47cb3   梁灏   fixed Table multi...
24
25
                                  <i class="ivu-icon ivu-icon-arrow-up-b" :class="{on: getColumn(rowIndex, index)._sortType === 'asc'}" @click="handleSort(getColumn(rowIndex, index)._index, 'asc')"></i>
                                  <i class="ivu-icon ivu-icon-arrow-down-b" :class="{on: getColumn(rowIndex, index)._sortType === 'desc'}" @click="handleSort(getColumn(rowIndex, index)._index, 'desc')"></i>
52874e27   梁灏   update Table
26
                              </span>
adaeca88   梁灏   update Table
27
                              <Poptip
5d0499ce   梁灏   update Table
28
                                  v-if="isPopperShow(column)"
9ea47cb3   梁灏   fixed Table multi...
29
                                  v-model="getColumn(rowIndex, index)._filterVisible"
adaeca88   梁灏   update Table
30
                                  placement="bottom"
19c208d3   梁灏   Poptip add prop `...
31
32
                                  popper-class="ivu-table-popper"
                                  transfer
9ea47cb3   梁灏   fixed Table multi...
33
                                  @on-popper-hide="handleFilterHide(getColumn(rowIndex, index)._index)">
642299b9   梁灏   update Table
34
                                  <span :class="[prefixCls + '-filter']">
9ea47cb3   梁灏   fixed Table multi...
35
                                      <i class="ivu-icon ivu-icon-funnel" :class="{on: getColumn(rowIndex, index)._isFiltered}"></i>
642299b9   梁灏   update Table
36
                                  </span>
9ea47cb3   梁灏   fixed Table multi...
37
                                  <div slot="content" :class="[prefixCls + '-filter-list']" v-if="getColumn(rowIndex, index)._filterMultiple">
99f80db0   梁灏   update Table
38
                                      <div :class="[prefixCls + '-filter-list-item']">
9ea47cb3   梁灏   fixed Table multi...
39
                                          <checkbox-group v-model="getColumn(rowIndex, index)._filterChecked">
ceeb9361   梁灏   fixed Table bug i...
40
                                              <checkbox v-for="(item, index) in column.filters" :key="index" :label="item.value">{{ item.label }}</checkbox>
99f80db0   梁灏   update Table
41
42
                                          </checkbox-group>
                                      </div>
99f80db0   梁灏   update Table
43
                                      <div :class="[prefixCls + '-filter-footer']">
9ea47cb3   梁灏   fixed Table multi...
44
45
                                          <i-button type="text" size="small" :disabled="!getColumn(rowIndex, index)._filterChecked.length" @click.native="handleFilter(getColumn(rowIndex, index)._index)">{{ t('i.table.confirmFilter') }}</i-button>
                                          <i-button type="text" size="small" @click.native="handleReset(getColumn(rowIndex, index)._index)">{{ t('i.table.resetFilter') }}</i-button>
99f80db0   梁灏   update Table
46
                                      </div>
642299b9   梁灏   update Table
47
                                  </div>
adaeca88   梁灏   update Table
48
                                  <div slot="content" :class="[prefixCls + '-filter-list']" v-else>
d0e206c5   梁灏   Table add content...
49
                                      <ul :class="[prefixCls + '-filter-list-single']">
45e7ed7e   梁灏   update Table
50
                                          <li
9ea47cb3   梁灏   fixed Table multi...
51
52
                                              :class="itemAllClasses(getColumn(rowIndex, index))"
                                              @click="handleReset(getColumn(rowIndex, index)._index)">{{ t('i.table.clearFilter') }}</li>
45e7ed7e   梁灏   update Table
53
                                          <li
9ea47cb3   梁灏   fixed Table multi...
54
                                              :class="itemClasses(getColumn(rowIndex, index), item)"
45e7ed7e   梁灏   update Table
55
                                              v-for="item in column.filters"
9ea47cb3   梁灏   fixed Table multi...
56
                                              @click="handleSelect(getColumn(rowIndex, index)._index, item.value)">{{ item.label }}</li>
adaeca88   梁灏   update Table
57
58
                                      </ul>
                                  </div>
642299b9   梁灏   update Table
59
                              </Poptip>
52874e27   梁灏   update Table
60
                          </template>
7f34c510   梁灏   update Table
61
62
                      </div>
                  </th>
eec3859c   huanghong   fixed table scollbar
63
                  
75803add   huanghong   fixed scoll bar
64
                  <th v-if="$parent.showVerticalScrollBar && rowIndex===0" :class='scrollBarCellClass()' :rowspan="headRows.length"></th>
7f34c510   梁灏   update Table
65
66
67
              </tr>
          </thead>
      </table>
2cb8a6d9   梁灏   commit Table comp...
68
69
  </template>
  <script>
99f80db0   梁灏   update Table
70
      import CheckboxGroup from '../checkbox/checkbox-group.vue';
0d136465   梁灏   update Table
71
      import Checkbox from '../checkbox/checkbox.vue';
642299b9   梁灏   update Table
72
      import Poptip from '../poptip/poptip.vue';
99f80db0   梁灏   update Table
73
      import iButton from '../button/button.vue';
096f2bfe   梁灏   fixed #1357
74
      import renderHeader from './header';
0d136465   梁灏   update Table
75
      import Mixin from './mixin';
4ab11811   梁灏   some component su...
76
      import Locale from '../../mixins/locale';
0d136465   梁灏   update Table
77
  
2cb8a6d9   梁灏   commit Table comp...
78
      export default {
486d4fda   梁灏   update Table
79
          name: 'TableHead',
4ab11811   梁灏   some component su...
80
          mixins: [ Mixin, Locale ],
096f2bfe   梁灏   fixed #1357
81
          components: { CheckboxGroup, Checkbox, Poptip, iButton, renderHeader },
2cb8a6d9   梁灏   commit Table comp...
82
83
          props: {
              prefixCls: String,
486d4fda   梁灏   update Table
84
              styleObject: Object,
0d136465   梁灏   update Table
85
              columns: Array,
d3dfdb26   梁灏   update Table
86
              objData: Object,
6c99b9fe   梁灏   update Table
87
              data: Array,    // rebuildData
224a3ae5   梁灏   publish 0.9.9-rc-3
88
              columnsWidth: Object,
5d0499ce   梁灏   update Table
89
90
91
              fixed: {
                  type: [Boolean, String],
                  default: false
1acabf79   梁灏   Table support mul...
92
              },
c1e965c3   梁灏   fixed-head
93
94
              columnRows: Array,
              fixedColumnRows: Array
2cb8a6d9   梁灏   commit Table comp...
95
          },
2cb8a6d9   梁灏   commit Table comp...
96
          computed: {
a404bbae   梁灏   update Table #167
97
              styles () {
486d4fda   梁灏   update Table
98
                  const style = Object.assign({}, this.styleObject);
eec3859c   huanghong   fixed table scollbar
99
                  const width = parseInt(this.styleObject.width) ;
a404bbae   梁灏   update Table #167
100
101
102
                  style.width = `${width}px`;
                  return style;
              },
0d136465   梁灏   update Table
103
              isSelectAll () {
d3dfdb26   梁灏   update Table
104
                  let isSelectAll = true;
63e0444e   梁灏   fixed #142
105
                  if (!this.data.length) isSelectAll = false;
17db7df4   梁灏   fixed #1751
106
                  if (!this.data.find(item => !item._disabled)) isSelectAll = false;    // #1751
6c99b9fe   梁灏   update Table
107
                  for (let i = 0; i < this.data.length; i++) {
cd85c675   leonine   修改_checked=true 时...
108
                      if (!this.objData[this.data[i]._index]._isChecked && !this.objData[this.data[i]._index]._isDisabled) {
6c99b9fe   梁灏   update Table
109
110
111
                          isSelectAll = false;
                          break;
                      }
d3dfdb26   梁灏   update Table
112
113
                  }
  
cd85c675   leonine   修改_checked=true 时...
114
                  return isSelectAll;
1acabf79   梁灏   Table support mul...
115
116
117
              },
              headRows () {
                  const isGroup = this.columnRows.length > 1;
c1e965c3   梁灏   fixed-head
118
119
120
121
122
                  if (isGroup) {
                      return this.fixed ? this.fixedColumnRows : this.columnRows;
                  } else {
                      return [this.columns];
                  }
0d136465   梁灏   update Table
123
              }
2cb8a6d9   梁灏   commit Table comp...
124
125
          },
          methods: {
c6f21c2f   jingsam   :bug: fix ie bug
126
127
128
129
130
131
              cellClasses (column) {
                  return [
                      `${this.prefixCls}-cell`,
                      {
                          [`${this.prefixCls}-hidden`]: !this.fixed && column.fixed && (column.fixed === 'left' || column.fixed === 'right')
                      }
b0893113   jingsam   :art: add eslint
132
                  ];
c6f21c2f   jingsam   :bug: fix ie bug
133
              },
75803add   huanghong   fixed scoll bar
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
              scrollBarCellClass(){
                  let hasRightFixed = false;
                  for(var i in this.headRows){
                      for(var j in this.headRows[i]){
                          if(this.headRows[i][j].fixed === 'right') {
                              hasRightFixed=true;
                              break;
                          }
                          if(hasRightFixed) break;
                      }
                  }
                  return [
                      {
                          [`${this.prefixCls}-hidden`]: hasRightFixed
                      }
                  ];
              },
89670198   梁灏   publish 0.9.9-rc-5
151
152
153
154
155
156
              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
157
                  ];
89670198   梁灏   publish 0.9.9-rc-5
158
159
160
161
162
163
164
              },
              itemAllClasses (column) {
                  return [
                      `${this.prefixCls}-filter-select-item`,
                      {
                          [`${this.prefixCls}-filter-select-item-selected`]: !column._filterChecked.length
                      }
b0893113   jingsam   :art: add eslint
165
                  ];
89670198   梁灏   publish 0.9.9-rc-5
166
              },
0d136465   梁灏   update Table
167
168
              selectAll () {
                  const status = !this.isSelectAll;
3d9e4f20   梁灏   update Table
169
                  this.$parent.selectAll(status);
52874e27   梁灏   update Table
170
              },
35ad3764   梁灏   update Table
171
              handleSort (index, type) {
b34e09b8   梁灏   fixed #2832
172
173
174
175
                  const column = this.columns[index];
                  const _index = column._index;
  
                  if (column._sortType === type) {
35ad3764   梁灏   update Table
176
                      type = 'normal';
741b987a   梁灏   update Table
177
                  }
b34e09b8   梁灏   fixed #2832
178
                  this.$parent.handleSort(_index, type);
642299b9   梁灏   update Table
179
              },
1b737fdc   梁灏   fixed #122
180
181
182
183
184
185
186
187
188
189
190
191
192
              handleSortByHead (index) {
                  const column = this.columns[index];
                  if (column.sortable) {
                      const type = column._sortType;
                      if (type === 'normal') {
                          this.handleSort(index, 'asc');
                      } else if (type === 'asc') {
                          this.handleSort(index, 'desc');
                      } else {
                          this.handleSort(index, 'normal');
                      }
                  }
              },
642299b9   梁灏   update Table
193
              handleFilter (index) {
adaeca88   梁灏   update Table
194
                  this.$parent.handleFilter(index);
99f80db0   梁灏   update Table
195
              },
45e7ed7e   梁灏   update Table
196
197
198
              handleSelect (index, value) {
                  this.$parent.handleFilterSelect(index, value);
              },
99f80db0   梁灏   update Table
199
              handleReset (index) {
adaeca88   梁灏   update Table
200
                  this.$parent.handleFilterReset(index);
99f80db0   梁灏   update Table
201
              },
adaeca88   梁灏   update Table
202
203
              handleFilterHide (index) {
                  this.$parent.handleFilterHide(index);
9ea47cb3   梁灏   fixed Table multi...
204
205
206
207
208
              },
              // 因为表头嵌套不是深拷贝,所以没有 _ 开头的方法,在 isGroup 下用此列
              getColumn (rowIndex, index) {
                  const isGroup = this.columnRows.length > 1;
                  return isGroup ? this.columns[rowIndex] : this.headRows[rowIndex][index];
2cb8a6d9   梁灏   commit Table comp...
209
210
              }
          }
b0893113   jingsam   :art: add eslint
211
212
      };
  </script>