当前位置:   article > 正文

el-table表格select下拉框可编辑 默认隐藏select下拉框 点击展示 选中之后在隐藏_el-table点击单元格显示下拉框

el-table点击单元格显示下拉框
  1. <el-table ref="table" v-loading="loading" :data="roleList" @cell-click="editCell" >
  2. <el-table-column align="center" label="展示方式" show-overflow-tooltip type="name" width="200">
  3. <template slot-scope="scope">
  4. <el-select
  5. :ref="`name-${scope.row.id}`"
  6. v-model="scope.row.technicalParamName"
  7. v-show="scope.row.id === tabClickId && tabClickLabel === '展示方式'"
  8. placeholder="选择展示方式"
  9. @change="inputBlur(scope.row)"
  10. @blur="inputBlur(scope.row)">
  11. <el-option
  12. v-for="option in nameOptions"
  13. :key="option.value"
  14. :label="option.label"
  15. :value="option.value"
  16. ></el-option>
  17. </el-select>
  18. <div class="cell-text" v-show="scope.row.id !== tabClickId || tabClickLabel !== '展示方式'">{{ scope.row.technicalParamName }}</div>
  19. </template>
  20. </el-table-column>
  21. </el-table>
  22. 方法如下
  23. // 失去焦点初始化
  24. inputBlur(item) {
  25. this.tabClickId = "";
  26. this.tabClickLabel = "";
  27. //这里还可以进行其他数据提交等操作
  28. },
  29. editCell(item, column, cell, event){
  30. //根据点击的单元格判断是否可变成下拉框
  31. switch (column.label) {
  32. case '序号': //当为序号时不变成输入框
  33. return
  34. default:
  35. this.tabClickId = item.id
  36. this.tabClickLabel = column.label
  37. break
  38. }
  39. //输入框默认获取焦点
  40. if (column.property === 'name') {
  41. const refName = `name-${row.id}`;
  42. this.$nextTick(() => {
  43. this.$refs[refName].focus();
  44. });
  45. }
  46. },
  47. data中的变量
  48. tabClickId: '',
  49. tabClickLabel: ''

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/114878
推荐阅读
相关标签
  

闽ICP备14008679号