Blame view

src/components/table/table-head.vue 8.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>
486d4fda   梁灏   update Table
4
              <col v-for="(column, index) in columns" :width="setCellWidth(column, index, true)">
7f34c510   梁灏   update Table
5
6
7
          </colgroup>
          <thead>
              <tr>
486d4fda   梁灏   update Table
8
                  <th v-for="(column, index) in columns" :class="alignCls(column)">
c6f21c2f   jingsam   :bug: fix ie bug
9
                      <div :class="cellClasses(column)">
8a392d25   梁灏   Table expand supp...
10
11
12
13
                          <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>
08fd628d   Aresn   Table support expand
14
                          <template v-else-if="column.type === 'selection'"><Checkbox :value="isSelectAll" @on-change="selectAll"></Checkbox></template>
52874e27   梁灏   update Table
15
                          <template v-else>
1b737fdc   梁灏   fixed #122
16
                              <span v-if="!column.renderHeader" @click="handleSortByHead(index)">{{ column.title || '#' }}</span>
096f2bfe   梁灏   fixed #1357
17
                              <render-header v-else :render="column.renderHeader" :column="column" :index="index"></render-header>
52874e27   梁灏   update Table
18
                              <span :class="[prefixCls + '-sort']" v-if="column.sortable">
486d4fda   梁灏   update Table
19
20
                                  <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
21
                              </span>
adaeca88   梁灏   update Table
22
                              <Poptip
5d0499ce   梁灏   update Table
23
                                  v-if="isPopperShow(column)"
644c37b3   梁灏   update License
24
                                  v-model="column._filterVisible"
adaeca88   梁灏   update Table
25
                                  placement="bottom"
486d4fda   梁灏   update Table
26
                                  @on-popper-hide="handleFilterHide(index)">
642299b9   梁灏   update Table
27
                                  <span :class="[prefixCls + '-filter']">
99f80db0   梁灏   update Table
28
                                      <i class="ivu-icon ivu-icon-funnel" :class="{on: column._isFiltered}"></i>
642299b9   梁灏   update Table
29
                                  </span>
adaeca88   梁灏   update Table
30
                                  <div slot="content" :class="[prefixCls + '-filter-list']" v-if="column._filterMultiple">
99f80db0   梁灏   update Table
31
                                      <div :class="[prefixCls + '-filter-list-item']">
486d4fda   梁灏   update Table
32
                                          <checkbox-group v-model="column._filterChecked">
68b308ee   梁灏   fixex #1353
33
                                              <checkbox v-for="item in column.filters" :key="column._columnKey" :label="item.value">{{ item.label }}</checkbox>
99f80db0   梁灏   update Table
34
35
                                          </checkbox-group>
                                      </div>
99f80db0   梁灏   update Table
36
                                      <div :class="[prefixCls + '-filter-footer']">
486d4fda   梁灏   update Table
37
38
                                          <i-button type="text" size="small" :disabled="!column._filterChecked.length" @click.native="handleFilter(index)">{{ t('i.table.confirmFilter') }}</i-button>
                                          <i-button type="text" size="small" @click.native="handleReset(index)">{{ t('i.table.resetFilter') }}</i-button>
99f80db0   梁灏   update Table
39
                                      </div>
642299b9   梁灏   update Table
40
                                  </div>
adaeca88   梁灏   update Table
41
                                  <div slot="content" :class="[prefixCls + '-filter-list']" v-else>
d0e206c5   梁灏   Table add content...
42
                                      <ul :class="[prefixCls + '-filter-list-single']">
45e7ed7e   梁灏   update Table
43
                                          <li
89670198   梁灏   publish 0.9.9-rc-5
44
                                              :class="itemAllClasses(column)"
486d4fda   梁灏   update Table
45
                                              @click="handleReset(index)">{{ t('i.table.clearFilter') }}</li>
45e7ed7e   梁灏   update Table
46
                                          <li
89670198   梁灏   publish 0.9.9-rc-5
47
                                              :class="itemClasses(column, item)"
45e7ed7e   梁灏   update Table
48
49
                                              v-for="item in column.filters"
                                              @click="handleSelect(index, item.value)">{{ item.label }}</li>
adaeca88   梁灏   update Table
50
51
                                      </ul>
                                  </div>
642299b9   梁灏   update Table
52
                              </Poptip>
52874e27   梁灏   update Table
53
                          </template>
7f34c510   梁灏   update Table
54
55
56
57
58
                      </div>
                  </th>
              </tr>
          </thead>
      </table>
2cb8a6d9   梁灏   commit Table comp...
59
60
  </template>
  <script>
99f80db0   梁灏   update Table
61
      import CheckboxGroup from '../checkbox/checkbox-group.vue';
0d136465   梁灏   update Table
62
      import Checkbox from '../checkbox/checkbox.vue';
642299b9   梁灏   update Table
63
      import Poptip from '../poptip/poptip.vue';
99f80db0   梁灏   update Table
64
      import iButton from '../button/button.vue';
096f2bfe   梁灏   fixed #1357
65
      import renderHeader from './header';
0d136465   梁灏   update Table
66
      import Mixin from './mixin';
4ab11811   梁灏   some component su...
67
      import Locale from '../../mixins/locale';
0d136465   梁灏   update Table
68
  
2cb8a6d9   梁灏   commit Table comp...
69
      export default {
486d4fda   梁灏   update Table
70
          name: 'TableHead',
4ab11811   梁灏   some component su...
71
          mixins: [ Mixin, Locale ],
096f2bfe   梁灏   fixed #1357
72
          components: { CheckboxGroup, Checkbox, Poptip, iButton, renderHeader },
2cb8a6d9   梁灏   commit Table comp...
73
74
          props: {
              prefixCls: String,
486d4fda   梁灏   update Table
75
              styleObject: Object,
0d136465   梁灏   update Table
76
              columns: Array,
d3dfdb26   梁灏   update Table
77
              objData: Object,
6c99b9fe   梁灏   update Table
78
              data: Array,    // rebuildData
224a3ae5   梁灏   publish 0.9.9-rc-3
79
              columnsWidth: Object,
5d0499ce   梁灏   update Table
80
81
82
83
              fixed: {
                  type: [Boolean, String],
                  default: false
              }
2cb8a6d9   梁灏   commit Table comp...
84
          },
2cb8a6d9   梁灏   commit Table comp...
85
          computed: {
a404bbae   梁灏   update Table #167
86
              styles () {
486d4fda   梁灏   update Table
87
88
                  const style = Object.assign({}, this.styleObject);
                  const width = this.$parent.bodyHeight === 0 ? parseInt(this.styleObject.width) : parseInt(this.styleObject.width) + this.$parent.scrollBarWidth;
a404bbae   梁灏   update Table #167
89
90
91
                  style.width = `${width}px`;
                  return style;
              },
0d136465   梁灏   update Table
92
              isSelectAll () {
d3dfdb26   梁灏   update Table
93
                  let isSelectAll = true;
63e0444e   梁灏   fixed #142
94
                  if (!this.data.length) isSelectAll = false;
17db7df4   梁灏   fixed #1751
95
                  if (!this.data.find(item => !item._disabled)) isSelectAll = false;    // #1751
6c99b9fe   梁灏   update Table
96
                  for (let i = 0; i < this.data.length; i++) {
cd85c675   leonine   修改_checked=true 时...
97
                      if (!this.objData[this.data[i]._index]._isChecked && !this.objData[this.data[i]._index]._isDisabled) {
6c99b9fe   梁灏   update Table
98
99
100
                          isSelectAll = false;
                          break;
                      }
d3dfdb26   梁灏   update Table
101
102
                  }
  
cd85c675   leonine   修改_checked=true 时...
103
                  return isSelectAll;
0d136465   梁灏   update Table
104
              }
2cb8a6d9   梁灏   commit Table comp...
105
106
          },
          methods: {
c6f21c2f   jingsam   :bug: fix ie bug
107
108
109
110
111
112
              cellClasses (column) {
                  return [
                      `${this.prefixCls}-cell`,
                      {
                          [`${this.prefixCls}-hidden`]: !this.fixed && column.fixed && (column.fixed === 'left' || column.fixed === 'right')
                      }
b0893113   jingsam   :art: add eslint
113
                  ];
c6f21c2f   jingsam   :bug: fix ie bug
114
              },
89670198   梁灏   publish 0.9.9-rc-5
115
116
117
118
119
120
              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
121
                  ];
89670198   梁灏   publish 0.9.9-rc-5
122
123
124
125
126
127
128
              },
              itemAllClasses (column) {
                  return [
                      `${this.prefixCls}-filter-select-item`,
                      {
                          [`${this.prefixCls}-filter-select-item-selected`]: !column._filterChecked.length
                      }
b0893113   jingsam   :art: add eslint
129
                  ];
89670198   梁灏   publish 0.9.9-rc-5
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
              },
1b737fdc   梁灏   fixed #122
141
142
143
144
145
146
147
148
149
150
151
152
153
              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
154
              handleFilter (index) {
adaeca88   梁灏   update Table
155
                  this.$parent.handleFilter(index);
99f80db0   梁灏   update Table
156
              },
45e7ed7e   梁灏   update Table
157
158
159
              handleSelect (index, value) {
                  this.$parent.handleFilterSelect(index, value);
              },
99f80db0   梁灏   update Table
160
              handleReset (index) {
adaeca88   梁灏   update Table
161
                  this.$parent.handleFilterReset(index);
99f80db0   梁灏   update Table
162
              },
adaeca88   梁灏   update Table
163
164
              handleFilterHide (index) {
                  this.$parent.handleFilterHide(index);
2cb8a6d9   梁灏   commit Table comp...
165
166
              }
          }
b0893113   jingsam   :art: add eslint
167
168
      };
  </script>