|
| 1 | +import * as VTable from '../../src'; |
| 2 | +import { bindDebugTool } from '../../src/scenegraph/debug-tool'; |
| 3 | +const CONTAINER_ID = 'vTable'; |
| 4 | +const generatePersons = count => { |
| 5 | + return Array.from(new Array(count)).map((_, i) => ({ |
| 6 | + id: i + 1, |
| 7 | + email1: `${i + 1}@xxx.com`, |
| 8 | + name: `小明${i + 1}`, |
| 9 | + lastName: '王', |
| 10 | + date1: '2022年9月1日', |
| 11 | + tel: '000-0000-0000', |
| 12 | + sex: i % 2 === 0 ? 'boy' : 'girl', |
| 13 | + work: i % 2 === 0 ? 'back-end engineer' : 'front-end engineer', |
| 14 | + city: 'beijing' |
| 15 | + })); |
| 16 | +}; |
| 17 | + |
| 18 | +export function createTable() { |
| 19 | + const records = generatePersons(20); |
| 20 | + const columns: VTable.ColumnsDefine = [ |
| 21 | + { |
| 22 | + field: 'id', |
| 23 | + title: 'ID', |
| 24 | + width: '1%', |
| 25 | + minWidth: 200, |
| 26 | + sort: true |
| 27 | + }, |
| 28 | + { |
| 29 | + field: 'email1', |
| 30 | + title: 'email', |
| 31 | + width: 200, |
| 32 | + sort: true |
| 33 | + }, |
| 34 | + { |
| 35 | + title: 'full name', |
| 36 | + columns: [ |
| 37 | + { |
| 38 | + field: 'name', |
| 39 | + title: 'First Name', |
| 40 | + width: 200 |
| 41 | + }, |
| 42 | + { |
| 43 | + field: 'name', |
| 44 | + title: 'Last Name', |
| 45 | + width: 200 |
| 46 | + } |
| 47 | + ] |
| 48 | + }, |
| 49 | + |
| 50 | + { |
| 51 | + field: 'tel', |
| 52 | + title: 'telephone', |
| 53 | + width: 150 |
| 54 | + }, |
| 55 | + { |
| 56 | + field: 'work', |
| 57 | + title: 'job', |
| 58 | + width: 200 |
| 59 | + }, |
| 60 | + { |
| 61 | + field: 'city', |
| 62 | + title: 'city', |
| 63 | + width: 150 |
| 64 | + } |
| 65 | + ]; |
| 66 | + const option: VTable.ListTableConstructorOptions = { |
| 67 | + container: document.getElementById(CONTAINER_ID), |
| 68 | + records, |
| 69 | + columns, |
| 70 | + tooltip: { |
| 71 | + isShowOverflowTextTooltip: true |
| 72 | + }, |
| 73 | + pagination: { |
| 74 | + perPageCount: 10, |
| 75 | + currentPage: 0 |
| 76 | + }, |
| 77 | + rowSeriesNumber: { |
| 78 | + title: '行号', |
| 79 | + dragOrder: true, |
| 80 | + headerStyle: { |
| 81 | + bgColor: '#EEF1F5', |
| 82 | + borderColor: '#e1e4e8' |
| 83 | + }, |
| 84 | + style: { |
| 85 | + borderColor: '#e1e4e8' |
| 86 | + } |
| 87 | + }, |
| 88 | + select: { |
| 89 | + // headerSelectMode: 'body', |
| 90 | + cornerHeaderSelectMode: 'cell' |
| 91 | + } |
| 92 | + // bottomFrozenRowCount: 1 |
| 93 | + // autoWrapText: true, |
| 94 | + // heightMode: 'autoHeight', |
| 95 | + // widthMode: 'adaptive' |
| 96 | + }; |
| 97 | + const tableInstance = new VTable.ListTable(option); |
| 98 | + window.tableInstance = tableInstance; |
| 99 | + |
| 100 | + // bindDebugTool(tableInstance.scenegraph.stage, { customGrapicKeys: ['col', 'row'] }); |
| 101 | + // tableInstance.on('sort_click', args => { |
| 102 | + // tableInstance.updateSortState( |
| 103 | + // { |
| 104 | + // field: args.field, |
| 105 | + // order: Date.now() % 3 === 0 ? 'desc' : Date.now() % 3 === 1 ? 'asc' : 'normal' |
| 106 | + // }, |
| 107 | + // false |
| 108 | + // ); |
| 109 | + // return false; //return false代表不执行内部排序逻辑 |
| 110 | + // }); |
| 111 | +} |
0 commit comments