当前位置:   article > 正文

详解element-ui el-table表格中勾选checkbox(selection),高亮当前行高亮某一行(某一行设置特殊的样式)_el-table checkbox

el-table checkbox

  1. <template>
  2. <el-table
  3. class="table"
  4. ref="table"
  5. :data="tableData"
  6. :row-class-name="row_class_name"
  7. @selection-change="selection_change"
  8. @row-click="row_click">
  9. <el-table-column type="selection" width="50" />
  10. <el-table-column prop="value" label="序号" width="50" />
  11. <el-table-column prop="label" label="列名" minWidth="100" />
  12. </el-table>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. selection: [],
  19. tableData: [
  20. { label: '显示文本1', value: 1 },
  21. { label: '显示文本2', value: 2 },
  22. { label: '显示文本3', value: 3 },
  23. { label: '显示文本4', value: 4 },
  24. { label: '显示文本5', value: 5 },
  25. ],
  26. }
  27. },
  28. methods: {
  29. row_class_name({ row, rowIndex }) {
  30. return this.selection.find(v => v.value == row.value) ? 'selected' : '';
  31. },
  32. selection_change(selection) {
  33. this.selection = selection;
  34. },
  35. row_click(row, column, event) {
  36. this.$refs.table.toggleRowSelection(row)
  37. },
  38. }
  39. };
  40. </script>
  41. <style lang="scss" scoped>
  42. .table {
  43. >>>tr.selected {
  44. $backgroundColor: #E6A23C; // 高亮选中行背景色
  45. background-color: $backgroundColor ;
  46. td {
  47. background-color: $backgroundColor !important;
  48. }
  49. }
  50. }
  51. </style>

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

闽ICP备14008679号