Blame view

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