|
| 1 | +import React, { useState } from 'react' |
| 2 | +import { ARFilterTable, FilterType } from '@accelhack-org/react-components' |
| 3 | + |
| 4 | +export const SampleFilterTable = () => { |
| 5 | + const _filterTable = new ARFilterTable.Class({ |
| 6 | + filters: [ |
| 7 | + { type: FilterType.TEXT, name: '検索ワード', field: 'word' }, |
| 8 | + { |
| 9 | + type: FilterType.TOGGLE, |
| 10 | + name: '大文字・小文字', |
| 11 | + field: 'font', |
| 12 | + options: [ |
| 13 | + { caption: 'ABC', value: 'upper' }, |
| 14 | + { caption: 'abc', value: 'lower' }, |
| 15 | + ], |
| 16 | + }, |
| 17 | + { |
| 18 | + type: FilterType.SELECTABLE, |
| 19 | + name: '言語', |
| 20 | + field: 'language', |
| 21 | + maxCount: 2, |
| 22 | + options: [ |
| 23 | + { caption: 'English', value: 'en' }, |
| 24 | + { caption: 'Japanese', value: 'ja' }, |
| 25 | + { caption: 'French', value: 'fr' }, |
| 26 | + ], |
| 27 | + }, |
| 28 | + ], |
| 29 | + options: { selectable: { enabled: true, identifier: 'id' } }, |
| 30 | + columns: [ |
| 31 | + { field: 'id', children: 'ID', sortable: true }, |
| 32 | + { field: 'name', children: '名前', sortable: true }, |
| 33 | + { field: 'desc', children: '説明' }, |
| 34 | + ], |
| 35 | + delegate: { |
| 36 | + getRows: async (limit, offset, sort, options) => { |
| 37 | + console.log(`getRows(${limit}, ${offset}, ${JSON.stringify(sort)}, ${JSON.stringify(options)})`) |
| 38 | + const rand = Math.floor(10 * Math.random() + 1) |
| 39 | + const rows = [ |
| 40 | + { id: 1, name: 'aa', desc: 'desc1' }, |
| 41 | + { id: 2, name: 'aa', desc: 'desc1' }, |
| 42 | + { id: 3, name: 'aa', desc: 'desc1' }, |
| 43 | + { id: 4, name: 'aa', desc: 'desc1' }, |
| 44 | + { id: 5, name: 'aa', desc: 'desc1' }, |
| 45 | + { id: 6, name: 'aa', desc: 'desc1' }, |
| 46 | + { id: 7, name: 'aa', desc: 'desc1' }, |
| 47 | + { id: 8, name: 'aa', desc: 'desc1' }, |
| 48 | + { id: 9, name: 'aa', desc: 'desc1' }, |
| 49 | + { id: 10, name: 'aa', desc: 'desc1' }, |
| 50 | + { id: 11, name: 'aa', desc: 'desc1' }, |
| 51 | + { id: 12, name: 'aa', desc: 'desc1' }, |
| 52 | + { id: 13, name: 'aa', desc: 'desc1' }, |
| 53 | + { id: 14, name: 'aa', desc: 'desc1' }, |
| 54 | + { id: 15, name: 'aa', desc: 'desc1' }, |
| 55 | + { id: 16, name: 'aa', desc: 'desc1' }, |
| 56 | + { id: 17, name: 'aa', desc: 'desc1' }, |
| 57 | + { id: 18, name: 'aa', desc: 'desc1' }, |
| 58 | + { id: 19, name: 'aa', desc: 'desc1' }, |
| 59 | + { id: 20, name: 'aa', desc: 'desc1' }, |
| 60 | + ].filter((r) => r.id % rand == 0) |
| 61 | + return { |
| 62 | + total: 10, |
| 63 | + rows: rows, |
| 64 | + } |
| 65 | + }, |
| 66 | + onRowClick: (row: any) => { |
| 67 | + console.log('onRowClick', row) |
| 68 | + }, |
| 69 | + onDataLoaded: () => { |
| 70 | + console.log('onDataLoaded') |
| 71 | + }, |
| 72 | + }, |
| 73 | + }) |
| 74 | + const [filterTable] = useState(_filterTable) |
| 75 | + return ( |
| 76 | + <div> |
| 77 | + <h2>Sample Table with Filter</h2> |
| 78 | + <div> |
| 79 | + <ARFilterTable.Component table={filterTable} /> |
| 80 | + <button |
| 81 | + onClick={() => { |
| 82 | + console.log('get Rows', filterTable.getRows()) |
| 83 | + }} |
| 84 | + > |
| 85 | + get Rows |
| 86 | + </button> |
| 87 | + <button |
| 88 | + onClick={() => { |
| 89 | + console.log('get selected rows', filterTable.getSelectedRows?.()) |
| 90 | + }} |
| 91 | + > |
| 92 | + get selected rows |
| 93 | + </button> |
| 94 | + </div> |
| 95 | + </div> |
| 96 | + ) |
| 97 | +} |
0 commit comments