|
| 1 | +:::anchor Base usage |
| 2 | + |
| 3 | +:::demo |
| 4 | + |
| 5 | +```html |
| 6 | +<template> |
| 7 | + <div> |
| 8 | + <ve-table |
| 9 | + :max-height="350" |
| 10 | + :columns="columns" |
| 11 | + :table-data="tableData" |
| 12 | + borderY |
| 13 | + :cell-autofill-option="cellAutofillOption" |
| 14 | + :edit-option="editOption" |
| 15 | + row-key-field-name="rowKey" |
| 16 | + :clipboard-option="clipboardOption" |
| 17 | + :virtual-scroll-option="virtualScrollOption" |
| 18 | + /> |
| 19 | + </div> |
| 20 | +</template> |
| 21 | + |
| 22 | +<script> |
| 23 | + export default { |
| 24 | + data() { |
| 25 | + return { |
| 26 | + // clipboard option |
| 27 | + clipboardOption: { |
| 28 | + copy: true, |
| 29 | + paste: true, |
| 30 | + cut: true, |
| 31 | + delete: true, |
| 32 | + beforeCopy: ({ data, selectionRangeIndexes, selectionRangeKeys }) => { |
| 33 | + console.log("beforeCopy"); |
| 34 | + this.log({ data, selectionRangeIndexes, selectionRangeKeys }); |
| 35 | + }, |
| 36 | + afterCopy: ({ data, selectionRangeIndexes, selectionRangeKeys }) => { |
| 37 | + console.log("afterCopy"); |
| 38 | + this.log({ data, selectionRangeIndexes, selectionRangeKeys }); |
| 39 | + }, |
| 40 | + beforePaste: ({ data, selectionRangeIndexes, selectionRangeKeys }) => { |
| 41 | + console.log("beforePaste"); |
| 42 | + this.log({ data, selectionRangeIndexes, selectionRangeKeys }); |
| 43 | + }, |
| 44 | + afterPaste: ({ data, selectionRangeIndexes, selectionRangeKeys }) => { |
| 45 | + console.log("afterPaste"); |
| 46 | + this.log({ data, selectionRangeIndexes, selectionRangeKeys }); |
| 47 | + }, |
| 48 | + beforeCut: ({ data, selectionRangeIndexes, selectionRangeKeys }) => { |
| 49 | + console.log("beforeCut"); |
| 50 | + this.log({ data, selectionRangeIndexes, selectionRangeKeys }); |
| 51 | + }, |
| 52 | + afterCut: ({ data, selectionRangeIndexes, selectionRangeKeys }) => { |
| 53 | + console.log("afterCut"); |
| 54 | + this.log({ data, selectionRangeIndexes, selectionRangeKeys }); |
| 55 | + }, |
| 56 | + beforeDelete: ({ data, selectionRangeIndexes, selectionRangeKeys }) => { |
| 57 | + return false; |
| 58 | +
|
| 59 | + console.log("beforeDelete"); |
| 60 | + this.log({ data, selectionRangeIndexes, selectionRangeKeys }); |
| 61 | + }, |
| 62 | + afterDelete: ({ data, selectionRangeIndexes, selectionRangeKeys }) => { |
| 63 | + console.log("afterDelete"); |
| 64 | + this.log({ data, selectionRangeIndexes, selectionRangeKeys }); |
| 65 | + }, |
| 66 | + }, |
| 67 | + virtualScrollOption: { |
| 68 | + // 是否开启 |
| 69 | + enable: false, |
| 70 | + }, |
| 71 | + cellAutofillOption: true, |
| 72 | + editOption: { |
| 73 | + // cell value change |
| 74 | + cellValueChange: ({ row, column }) => {}, |
| 75 | + }, |
| 76 | + columns: [ |
| 77 | + { |
| 78 | + field: "index", |
| 79 | + key: "index", |
| 80 | + operationColumn: true, |
| 81 | + title: "#", |
| 82 | + width: 35, |
| 83 | + align: "center", |
| 84 | + renderBodyCell: ({ row, column, rowIndex }, h) => { |
| 85 | + return ++rowIndex; |
| 86 | + }, |
| 87 | + }, |
| 88 | + { field: "col1", key: "col1", title: "Col1", edit: true, width: 150 }, |
| 89 | + { field: "col2", key: "col2", title: "Col2", edit: true, width: 150 }, |
| 90 | + { field: "col3", key: "col3", title: "Col3", edit: true, width: 150 }, |
| 91 | + { field: "col4", key: "col4", title: "Col4", edit: true, width: 150 }, |
| 92 | + { field: "col5", key: "col5", title: "Col5", edit: true, width: 150 }, |
| 93 | + { field: "col6", key: "col6", title: "Col6", edit: true, width: 150 }, |
| 94 | + ], |
| 95 | + tableData: [], |
| 96 | + }; |
| 97 | + }, |
| 98 | + methods: { |
| 99 | + initTableData() { |
| 100 | + let data = []; |
| 101 | + for (let i = 0; i < 100; i++) { |
| 102 | + data.push({ |
| 103 | + rowKey: `row${i}`, |
| 104 | + col1: `A${i + 1}`, |
| 105 | + col2: `B${i + 1}`, |
| 106 | + col3: `C${i + 1}`, |
| 107 | + col4: `D${i + 1}`, |
| 108 | + col5: `E${i + 1}`, |
| 109 | + col6: `F${i + 1}`, |
| 110 | + col7: `G${i + 1}`, |
| 111 | + col8: `H${i + 1}`, |
| 112 | + }); |
| 113 | + } |
| 114 | + this.tableData = data; |
| 115 | + }, |
| 116 | + log({ data, selectionRangeIndexes, selectionRangeKeys }) { |
| 117 | + console.log("data::", data); |
| 118 | + console.log("selectionRangeIndexes::", selectionRangeIndexes); |
| 119 | + console.log("selectionRangeKeys::", selectionRangeKeys); |
| 120 | + }, |
| 121 | + }, |
| 122 | + created() { |
| 123 | + this.initTableData(); |
| 124 | + }, |
| 125 | + }; |
| 126 | +</script> |
| 127 | +``` |
| 128 | + |
| 129 | +::: |
0 commit comments