Blame view

src/components/table/table-body.vue 4.83 KB
2cb8a6d9   梁灏   commit Table comp...
1
  <template>
486d4fda   梁灏   update Table
2
      <table cellspacing="0" cellpadding="0" border="0" :style="styleObject">
7f34c510   梁灏   update Table
3
          <colgroup>
eec3859c   huanghong   fixed table scollbar
4
              <col v-for="(column, index) in columns" :width="setCellWidth(column)">
7f34c510   梁灏   update Table
5
6
          </colgroup>
          <tbody :class="[prefixCls + '-tbody']">
08fd628d   Aresn   Table support expand
7
              <template v-for="(row, index) in data">
e40c5352   Aresn   fixed #1195
8
                  <table-tr
568ac30b   Aresn   change api name
9
                      :draggable="draggable"
e40c5352   Aresn   fixed #1195
10
                      :row="row"
76ae3e88   梁灏   fix #5380
11
                      :key="rowKey ? row._rowKey : index"
e40c5352   Aresn   fixed #1195
12
13
14
                      :prefix-cls="prefixCls"
                      @mouseenter.native.stop="handleMouseIn(row._index)"
                      @mouseleave.native.stop="handleMouseOut(row._index)"
8b530b1c   梁灏   fixed #1342
15
                      @click.native="clickCurrentRow(row._index)"
e40c5352   Aresn   fixed #1195
16
                      @dblclick.native.stop="dblclickCurrentRow(row._index)">
0e8bb0c1   other   更新
17
                      <td v-for="(column,colIndex) in columns" v-if="rowExpanderResult[index][colIndex]" :rowspan="rowExpanderResult[index][colIndex]" :class="alignCls(column, row)">
b55f59c6   Rookie_Zoe   fix #4258
18
                          <table-cell
08fd628d   Aresn   Table support expand
19
20
21
                              :fixed="fixed"
                              :prefix-cls="prefixCls"
                              :row="row"
68b308ee   梁灏   fixex #1353
22
                              :key="column._columnKey"
08fd628d   Aresn   Table support expand
23
24
25
26
27
28
                              :column="column"
                              :natural-index="index"
                              :index="row._index"
                              :checked="rowChecked(row._index)"
                              :disabled="rowDisabled(row._index)"
                              :expanded="rowExpanded(row._index)"
b55f59c6   Rookie_Zoe   fix #4258
29
                          ></table-cell>
08fd628d   Aresn   Table support expand
30
                      </td>
e40c5352   Aresn   fixed #1195
31
                  </table-tr>
55f90d87   梁灏   fixed #1648
32
                  <tr v-if="rowExpanded(row._index)" :class="{[prefixCls + '-expanded-hidden']: fixed}">
ccfe4714   other   更新
33
                      <td :colspan="columns.length"  :class="prefixCls + '-expanded-cell'">
76ae3e88   梁灏   fix #5380
34
                          <Expand :key="rowKey ? row._rowKey : index" :row="row" :render="expandRender" :index="row._index"></Expand>
08fd628d   Aresn   Table support expand
35
36
37
                      </td>
                  </tr>
              </template>
7f34c510   梁灏   update Table
38
          </tbody>
3ef4dfb9   梁灏   update Table
39
      </table>
2cb8a6d9   梁灏   commit Table comp...
40
41
  </template>
  <script>
6cadeba4   梁灏   support Message
42
      // todo :key="row"
e40c5352   Aresn   fixed #1195
43
      import TableTr from './table-tr.vue';
b55f59c6   Rookie_Zoe   fix #4258
44
      import TableCell from './cell.vue';
718e773f   刘荣   -
45
      import Expand from './expand.js';
7f34c510   梁灏   update Table
46
47
      import Mixin from './mixin';
  
2cb8a6d9   梁灏   commit Table comp...
48
      export default {
486d4fda   梁灏   update Table
49
          name: 'TableBody',
7f34c510   梁灏   update Table
50
          mixins: [ Mixin ],
b55f59c6   Rookie_Zoe   fix #4258
51
          components: { TableCell, Expand, TableTr },
2cb8a6d9   梁灏   commit Table comp...
52
          props: {
7f34c510   梁灏   update Table
53
              prefixCls: String,
486d4fda   梁灏   update Table
54
              styleObject: Object,
7f34c510   梁灏   update Table
55
              columns: Array,
741b987a   梁灏   update Table
56
              data: Array,    // rebuildData
741b987a   梁灏   update Table
57
              objData: Object,
224a3ae5   梁灏   publish 0.9.9-rc-3
58
              columnsWidth: Object,
5d0499ce   梁灏   update Table
59
60
61
              fixed: {
                  type: [Boolean, String],
                  default: false
7e8e6ef8   forfire   add dragdrop for tr
62
              },
568ac30b   Aresn   change api name
63
64
65
              draggable: {
                  type: Boolean,
                  default: false
76ae3e88   梁灏   fix #5380
66
67
68
69
              },
              rowKey: {
                  type: Boolean,
                  default: false
ccfe4714   other   更新
70
71
72
73
74
75
              },
              rowExpander: {
                  type: Function,
                  default: function(){
                      return 1;
                  }
5d0499ce   梁灏   update Table
76
              }
2cb8a6d9   梁灏   commit Table comp...
77
          },
08fd628d   Aresn   Table support expand
78
79
80
81
82
83
84
85
86
87
88
89
          computed: {
              expandRender () {
                  let render = function () {
                      return '';
                  };
                  for (let i = 0; i < this.columns.length; i++) {
                      const column = this.columns[i];
                      if (column.type && column.type === 'expand') {
                          if (column.render) render = column.render;
                      }
                  }
                  return render;
0e8bb0c1   other   更新
90
91
92
93
94
95
96
97
98
99
100
101
102
              },
              rowExpanderResult() {
                  const result = [];
                  for (let i = 0; i < this.data.length; i++) {
                      const row = this.data[i];
                      const span = [];
                      for (let j = 0; j < this.columns.length; j++) {
                          const column = this.columns[j];
                          span.push(this.rowExpander(row,column));
                      }
                      result.push(span);
                  }
                  return result;
08fd628d   Aresn   Table support expand
103
104
              }
          },
2cb8a6d9   梁灏   commit Table comp...
105
          methods: {
d3dfdb26   梁灏   update Table
106
              rowChecked (_index) {
97edb2eb   梁灏   update Table
107
                  return this.objData[_index] && this.objData[_index]._isChecked;
741b987a   梁灏   update Table
108
              },
0dcc9482   leonine   itable 添加禁用某行选中的功能
109
110
111
              rowDisabled(_index){
                  return this.objData[_index] && this.objData[_index]._isDisabled;
              },
08fd628d   Aresn   Table support expand
112
113
114
              rowExpanded(_index){
                  return this.objData[_index] && this.objData[_index]._isExpanded;
              },
d3dfdb26   梁灏   update Table
115
116
              handleMouseIn (_index) {
                  this.$parent.handleMouseIn(_index);
7f34c510   梁灏   update Table
117
              },
d3dfdb26   梁灏   update Table
118
119
              handleMouseOut (_index) {
                  this.$parent.handleMouseOut(_index);
7f34c510   梁灏   update Table
120
              },
da55375f   Rijn   Added click and d...
121
122
123
124
125
              clickCurrentRow (_index) {
                  this.$parent.clickCurrentRow(_index);
              },
              dblclickCurrentRow (_index) {
                  this.$parent.dblclickCurrentRow(_index);
7f34c510   梁灏   update Table
126
              }
2cb8a6d9   梁灏   commit Table comp...
127
          }
b0893113   jingsam   :art: add eslint
128
129
      };
  </script>