elementui Table合并单元格

喜欢ヅ旅行 2022-09-03 08:28 308阅读 0赞
  1. <template>
  2. <div class="">
  3. <el-table
  4. :data="listData"
  5. :span-method="objectSpanMethod"
  6. class="tableArea"
  7. style="width: 100%">
  8. <el-table-column
  9. prop="type"
  10. label="序号"
  11. align="center"
  12. width="200"/>
  13. <el-table-column
  14. prop="sheetType"
  15. label="工单类型"
  16. />
  17. <el-table-column
  18. prop="taskKey"
  19. label="taskKey"
  20. />
  21. <el-table-column
  22. prop="templateUrl"
  23. label="templateUrl"
  24. />
  25. <el-table-column
  26. label="操作"
  27. >
  28. <template slot-scope="scope">
  29. <el-tooltip class="item" effect="dark" content="修改" placement="top-start">
  30. <i class="el-icon-edit-outline" @click="modify(scope)" />
  31. </el-tooltip>
  32. <el-tooltip class="item" effect="dark" content="删除" placement="top-start">
  33. <i class="el-icon-delete" @click="deleteData(scope)" />
  34. </el-tooltip>
  35. </template>
  36. </el-table-column >
  37. </el-table>
  38. </div>
  39. </template>
  40. <script>
  41. export default {
  42. name: 'myNeedDeal',
  43. data() {
  44. return {
  45. rowList: [],
  46. spanArr: [],
  47. position: 0,
  48. listData: []
  49. }
  50. },
  51. methods: {
  52. queryData(){ //查询操作
  53. this.listData = [
  54. {
  55. id:1,
  56. type:1,
  57. sheetType: "事件单",
  58. taskKey: "shijian_01",
  59. templateUrl: "/shijian_01"
  60. },
  61. {
  62. id:2,
  63. type:1,
  64. sheetType: "事件单",
  65. taskKey: "shijian_02",
  66. templateUrl: "/shijian_02"
  67. },
  68. {
  69. id:3,
  70. type:1,
  71. sheetType: "事件单",
  72. taskKey: "shijian_03",
  73. templateUrl: "/shijian_04"
  74. },
  75. {
  76. id:4,
  77. type:2,
  78. sheetType: "问题单",
  79. taskKey: "wenti_01",
  80. templateUrl: "/wenti_01"
  81. },
  82. {
  83. id:5,
  84. type:2,
  85. sheetType: "问题单",
  86. taskKey: "wenti_02",
  87. templateUrl: "/wenti_02"
  88. },
  89. {
  90. id:6,
  91. type:2,
  92. sheetType: "问题单",
  93. taskKey: "wenti_03",
  94. templateUrl: "/wenti_03"
  95. }
  96. ];
  97. this.rowspan()
  98. },
  99. rowspan() {
  100. this.listData.forEach((item,index) => {
  101. if( index === 0){
  102. this.spanArr.push(1);
  103. this.position = 0;
  104. }else{
  105. if(this.listData[index].type === this.listData[index-1].type ){
  106. this.spanArr[this.position] += 1;
  107. this.spanArr.push(0);
  108. }else{
  109. this.spanArr.push(1);
  110. this.position = index;
  111. }
  112. }
  113. })
  114. },
  115. objectSpanMethod({ row, column, rowIndex, columnIndex }) { //表格合并行
  116. if (columnIndex === 0) {
  117. const _row = this.spanArr[rowIndex];
  118. const _col = _row>0 ? 1 : 0;
  119. return {
  120. rowspan: _row,
  121. colspan: _col
  122. }
  123. }
  124. if(columnIndex === 1){
  125. const _row = this.spanArr[rowIndex];
  126. const _col = _row>0 ? 1 : 0;
  127. return {
  128. rowspan: _row,
  129. colspan: _col
  130. }
  131. }
  132. }
  133. },
  134. mounted() {
  135. this.queryData();
  136. }
  137. }
  138. </script>
  139. <style lang="scss" scoped>
  140. .el-select {
  141. margin-right: 15px;
  142. }
  143. .el-input {
  144. margin-right: 15px;
  145. width: 200px;
  146. }
  147. .tableArea {
  148. margin-top: 20px;
  149. box-shadow: 0 0 8px 0 #aaa;
  150. }
  151. i[class^="el-icon"] {
  152. margin-right: 5px;
  153. font-size: 16px;
  154. cursor: pointer;
  155. }
  156. .modify_table{
  157. td{
  158. padding: 10px ;
  159. }
  160. }
  161. .item_title{
  162. text-align: right;
  163. }
  164. </style>

发表评论

表情:
评论列表 (有 0 条评论,308人围观)

还没有评论,来说两句吧...

相关阅读