|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <vxe-toolbar ref="toolbarRef" print export import custom></vxe-toolbar> |
| 4 | + |
| 5 | + <vxe-table |
| 6 | + border |
| 7 | + stripe |
| 8 | + resizable |
| 9 | + highlight-hover-row |
| 10 | + height="400" |
| 11 | + ref="tableRef" |
| 12 | + id="aaaa" |
| 13 | + :print-config="{}" |
| 14 | + :import-config="{}" |
| 15 | + :export-config="{}" |
| 16 | + :custom-config="{mode: 'drawer', storage: true}" |
| 17 | + :loading="demo1.loading" |
| 18 | + :expand-config="{iconOpen: 'vxe-icon-question-circle-fill', iconClose: 'vxe-icon-question-circle-fill'}" |
| 19 | + :checkbox-config="{labelField: 'id', highlight: true, range: true}" |
| 20 | + :data="demo1.tableData"> |
| 21 | + <vxe-column type="seq" width="60"></vxe-column> |
| 22 | + <vxe-column type="checkbox" title="ID" width="140"></vxe-column> |
| 23 | + <vxe-colgroup title="分组1" field="g1"> |
| 24 | + <vxe-column type="expand" field="role" title="Role"> |
| 25 | + <template #content="{ row }"> |
| 26 | + <div>{{ row.name }}</div> |
| 27 | + </template> |
| 28 | + </vxe-column> |
| 29 | + <vxe-column field="name" title="Name" sortable></vxe-column> |
| 30 | + </vxe-colgroup> |
| 31 | + <vxe-column field="sex11" title="Sex11" :visible="false"></vxe-column> |
| 32 | + <vxe-column field="sex" title="Sex" :filters="demo1.sexList" :filter-multiple="false" :formatter="formatterSex"></vxe-column> |
| 33 | + <vxe-column |
| 34 | + field="age" |
| 35 | + title="Age" |
| 36 | + sortable |
| 37 | + :filters="demo1.ageOptions" |
| 38 | + :filter-method="filterAgeMethod"></vxe-column> |
| 39 | + <vxe-column field="address" title="Address" show-overflow></vxe-column> |
| 40 | + </vxe-table> |
| 41 | + </div> |
| 42 | +</template> |
| 43 | + |
| 44 | +<script lang="ts" setup> |
| 45 | +import { onMounted, ref, reactive, nextTick } from 'vue' |
| 46 | +import { VxeColumnPropTypes, VxeTableInstance, VxeToolbarInstance } from '../../../types' |
| 47 | +
|
| 48 | +interface RowVO { |
| 49 | + [key: string]: any |
| 50 | +} |
| 51 | +
|
| 52 | +const tableRef = ref<VxeTableInstance<RowVO>>() |
| 53 | +const toolbarRef = ref<VxeToolbarInstance>() |
| 54 | +
|
| 55 | +const demo1 = reactive({ |
| 56 | + loading: false, |
| 57 | + tableData: [] as any[], |
| 58 | + sexList: [ |
| 59 | + { label: '女', value: '0' }, |
| 60 | + { label: '男', value: '1' } |
| 61 | + ], |
| 62 | + ageOptions: [ |
| 63 | + { label: '大于16岁', value: 16 }, |
| 64 | + { label: '大于26岁', value: 26 }, |
| 65 | + { label: '大于30岁', value: 30 }, |
| 66 | + { label: '大于30岁', value: 30 }, |
| 67 | + { label: '大于30岁', value: 30 }, |
| 68 | + { label: '大于30岁', value: 30 }, |
| 69 | + { label: '大于30岁', value: 30 }, |
| 70 | + { label: '大于30岁', value: 30 }, |
| 71 | + { label: '大于30岁', value: 30 }, |
| 72 | + { label: '大于30岁', value: 30 }, |
| 73 | + { label: '大于30岁', value: 30 }, |
| 74 | + { label: '大于30岁', value: 30 }, |
| 75 | + { label: '大于30岁', value: 30 }, |
| 76 | + { label: '大于30岁', value: 30 }, |
| 77 | + { label: '大于30岁', value: 30 }, |
| 78 | + { label: '大于30岁', value: 30 }, |
| 79 | + { label: '大于30岁', value: 30 }, |
| 80 | + { label: '大于30岁', value: 30 } |
| 81 | + ] |
| 82 | +}) |
| 83 | +
|
| 84 | +const formatterSex: VxeColumnPropTypes.Formatter = ({ cellValue }) => { |
| 85 | + const item = demo1.sexList.find(item => item.value === cellValue) |
| 86 | + return item ? item.label : '' |
| 87 | +} |
| 88 | +
|
| 89 | +const filterAgeMethod: VxeColumnPropTypes.FilterMethod = ({ value, row }) => { |
| 90 | + return row.age >= value |
| 91 | +} |
| 92 | +
|
| 93 | +onMounted(() => { |
| 94 | + demo1.loading = true |
| 95 | + setTimeout(() => { |
| 96 | + demo1.tableData = [ |
| 97 | + { id: 10001, name: 'Test1', role: 'Develop', sex: '0', age: 28, address: 'test abc' }, |
| 98 | + { id: 10002, name: 'Test2', role: 'Test', sex: '1', age: 22, address: 'Guangzhou' }, |
| 99 | + { id: 10003, name: 'Test3', role: 'PM', sex: '0', age: 32, address: 'Shanghai' }, |
| 100 | + { id: 10004, name: 'Test4', role: 'Designer', sex: '1', age: 23, address: 'test abc' }, |
| 101 | + { id: 10005, name: 'Test5', role: 'Develop', sex: '1', age: 30, address: 'Shanghai' }, |
| 102 | + { id: 10006, name: 'Test6', role: 'Designer', sex: '1', age: 21, address: 'test abc' }, |
| 103 | + { id: 10007, name: 'Test7', role: 'Test', sex: '0', age: 29, address: 'test abc' }, |
| 104 | + { id: 10008, name: 'Test8', role: 'Develop', sex: '0', age: 35, address: 'test abc' }, |
| 105 | + { id: 10009, name: 'Test9', role: 'Test', sex: '1', age: 21, address: 'test abc' }, |
| 106 | + { id: 10010, name: 'Test10', role: 'Develop', sex: '0', age: 28, address: 'test abc' }, |
| 107 | + { id: 10011, name: 'Test11', role: 'Test', sex: '0', age: 29, address: 'test abc' }, |
| 108 | + { id: 10012, name: 'Test12', role: 'Develop', sex: '1', age: 27, address: 'test abc' }, |
| 109 | + { id: 10013, name: 'Test13', role: 'Test', sex: '0', age: 24, address: 'test abc' }, |
| 110 | + { id: 10014, name: 'Test14', role: 'Develop', sex: '1', age: 34, address: 'test abc' }, |
| 111 | + { id: 10015, name: 'Test15', role: 'Test', sex: '1', age: 21, address: 'test abc' }, |
| 112 | + { id: 10016, name: 'Test16', role: 'Develop', sex: '0', age: 20, address: 'test abc' }, |
| 113 | + { id: 10017, name: 'Test17', role: 'Test', sex: '1', age: 31, address: 'test abc' }, |
| 114 | + { id: 10018, name: 'Test18', role: 'Develop', sex: '0', age: 32, address: 'test abc' }, |
| 115 | + { id: 10019, name: 'Test19', role: 'Test', sex: '1', age: 37, address: 'test abc' }, |
| 116 | + { id: 10020, name: 'Test20', role: 'Develop', sex: '1', age: 41, address: 'test abc' } |
| 117 | + ] |
| 118 | + demo1.loading = false |
| 119 | + }, 100) |
| 120 | +}) |
| 121 | +
|
| 122 | +nextTick(() => { |
| 123 | + // 将表格和工具栏进行关联 |
| 124 | + const $table = tableRef.value |
| 125 | + const $toolbar = toolbarRef.value |
| 126 | + if ($table && $toolbar) { |
| 127 | + $table.connect($toolbar) |
| 128 | + } |
| 129 | +}) |
| 130 | +</script> |
0 commit comments