Blame view

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