config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { getPropByPath } from 'element-ui/src/utils/util';
  2. export const cellStarts = {
  3. default: {
  4. order: ''
  5. },
  6. selection: {
  7. width: 48,
  8. minWidth: 48,
  9. realWidth: 48,
  10. order: '',
  11. className: 'el-table-column--selection'
  12. },
  13. expand: {
  14. width: 48,
  15. minWidth: 48,
  16. realWidth: 48,
  17. order: ''
  18. },
  19. index: {
  20. width: 48,
  21. minWidth: 48,
  22. realWidth: 48,
  23. order: ''
  24. }
  25. };
  26. // 这些选项不应该被覆盖
  27. export const cellForced = {
  28. selection: {
  29. renderHeader: function(h, { store }) {
  30. return <el-checkbox
  31. disabled={ store.states.data && store.states.data.length === 0 }
  32. indeterminate={ store.states.selection.length > 0 && !this.isAllSelected }
  33. nativeOn-click={ this.toggleAllSelection }
  34. value={ this.isAllSelected } />;
  35. },
  36. renderCell: function(h, { row, column, store, $index }) {
  37. return <el-checkbox
  38. nativeOn-click={ (event) => event.stopPropagation() }
  39. value={ store.isSelected(row) }
  40. disabled={ column.selectable ? !column.selectable.call(null, row, $index) : false }
  41. on-input={ () => { store.commit('rowSelectedChanged', row); } } />;
  42. },
  43. sortable: false,
  44. resizable: false
  45. },
  46. index: {
  47. renderHeader: function(h, { column }) {
  48. return column.label || '#';
  49. },
  50. renderCell: function(h, { $index, column }) {
  51. let i = $index + 1;
  52. const index = column.index;
  53. if (typeof index === 'number') {
  54. i = $index + index;
  55. } else if (typeof index === 'function') {
  56. i = index($index);
  57. }
  58. return <div>{ i }</div>;
  59. },
  60. sortable: false
  61. },
  62. expand: {
  63. renderHeader: function(h, { column }) {
  64. return column.label || '';
  65. },
  66. renderCell: function(h, { row, store }) {
  67. const classes = ['el-table__expand-icon'];
  68. if (store.states.expandRows.indexOf(row) > -1) {
  69. classes.push('el-table__expand-icon--expanded');
  70. }
  71. const callback = function(e) {
  72. e.stopPropagation();
  73. store.toggleRowExpansion(row);
  74. };
  75. return (<div class={ classes }
  76. on-click={callback}>
  77. <i class='el-icon el-icon-arrow-right'></i>
  78. </div>);
  79. },
  80. sortable: false,
  81. resizable: false,
  82. className: 'el-table__expand-column'
  83. }
  84. };
  85. export function defaultRenderCell(h, { row, column, $index }) {
  86. const property = column.property;
  87. const value = property && getPropByPath(row, property).v;
  88. if (column && column.formatter) {
  89. return column.formatter(row, column, value, $index);
  90. }
  91. return value;
  92. }
  93. export function treeCellPrefix(h, { row, treeNode, store }) {
  94. if (!treeNode) return null;
  95. const ele = [];
  96. const callback = function(e) {
  97. e.stopPropagation();
  98. store.loadOrToggle(row);
  99. };
  100. if (treeNode.indent) {
  101. ele.push(<span class="el-table__indent" style={{'padding-left': treeNode.indent + 'px'}}></span>);
  102. }
  103. if (typeof treeNode.expanded === 'boolean' && !treeNode.noLazyChildren) {
  104. const expandClasses = ['el-table__expand-icon', treeNode.expanded ? 'el-table__expand-icon--expanded' : ''];
  105. let iconClasses = ['el-icon-arrow-right'];
  106. if (treeNode.loading) {
  107. iconClasses = ['el-icon-loading'];
  108. }
  109. ele.push(<div class={ expandClasses }
  110. on-click={ callback }>
  111. <i class={ iconClasses }></i>
  112. </div>);
  113. } else {
  114. ele.push(<span class="el-table__placeholder"></span>);
  115. }
  116. return ele;
  117. }