Flex Table
Engilsh | 中文
FlexTable
is a library with native javascript that completely based on flex, without any table
html, it can be used to generate table quickly.
The core code of FlexTable
only contains rendering table functions, all the other features are provided by plugins, you can also add or replace plugins according to your own use.
Start
Use npm.
npm install --save @qmhc/flex-table
import FlexTable from '@qmhc/flex-table'
import '@qmhc/flex-table/dist/flex-table.css'
Import on demand.
import FlexTable from '@qmhc/flex-table/dist/flex-table.core'
import Sorter from '@qmhc/flex-table/dist/plugin/Sorter'
import '@qmhc/flex-table/dist/flex-table.core.css'
import '@qmhc/flex-table/dist/plugin/Sorter.css'
Use tags.
<script src="./dist/flex-table.js"></script>
<link rel="stylesheet" href="./dist/flex-table.css">
Import on demand.
<script src="../dist/flex-table.core.js"></script>
<script src="../dist/plugin/Sorter.js"></script>
<link rel="stylesheet" href="../dist/flex-table.core.css">
<link rel="stylesheet" href="../dist/plugin/Sorter.css">
Create a table.
const flexTable = new FlexTable({
container: '#app',
columns: [{ }],
data: [{ }],
plugins: {
}
})
Manually register plugins when import on demand.
FlexTable.registerPlugin('sorter', Sorter)
FlexTable.registerPlugin('sorter', FlexTable.Sorter)
Example
For a simple example see example/index.html
.
Online example click me
.
Config
A complete configuration.
{
container: '#app',
columns,
data,
deepClone: true,
observeData: true,
className: 'my-table',
id: 'myTable',
rowClassName: (data, index) => '',
stripe: true,
dangerous: false,
plugins: {
selector: {},
editor: {
trigger: 'action',
columnWidth: 142,
columnName: 'Action',
labels: {
edit: 'Edit',
save: 'Save',
cancel: 'Cancel'
}
},
resizer: {
force: false
},
order: {
renderer: index => `No.${index}`,
type: 'absolute',
columnWidth: 72,
columnName: 'Order'
}
sorter: {
multiple: true,
multipleKey: 'shift'
},
extender: {
renderer: data => {
const ul = document.createElement('ul')
ul.style.cssText = `
padding: 10px 50px;
list-style: none
`
const nameLi = document.createElement('li')
nameLi.textContent = `Full Name: ${data.firstName} ${data.lastName}`
const ageLi = nameLi.cloneNode()
ageLi.textContent = `Age: ${data.age}`
ul.appendChild(nameLi)
ul.appendChild(ageLi)
return ul
},
accordion: false,
transition: true
},
pager: {
useOptions: true,
pageOptions: [10, 15, 20, 25, 30],
currentPage: 1,
pageSize: 15,
labels: {
prev: 'Prev',
next: 'Next',
row: 'row'
}
},
filter: {
filterAll: false,
highlight: true,
},
layer: {
loading: false,
notFound: true,
delay: 500,
loadingText: 'Loading',
notFoundText: 'Not Found'
},
scroller: {
height: 450,
mouse: true,
wheel: false,
wheelDistance: 20
}
},
theme: 'light'
}
Complete configuration of columns
.
{
name: 'First Name',
accessor: (data, props) => data.firstName,
key: 'firstName',
footer: data => `Count: ${data.length}`,
resize: true,
sort: {
able: true,
type: 0,
method: (prev, next) => prev.toString().localeCompare(next)
},
filter: {
able: true,
type: 'text',
value: undefined,
method: (value, filter, origin, data) => {
if (value.includes(filter)) {
return true
}
},
},
edit: {
able: data => true,
type: 'select',
options: ['Kegdhi', 'Tshudgh', 'Asihvsit'],
verifier: value => true
}
defaultWidth: 100
}
Note: FlexTable
uses a strict comparison when parsing the configuration, for example, the default enabled property needs to be ===
to false
can disable it, vice versa.
Theme
FlexTable
has four theme, configure theme
property to use them.
{
theme: 'dark',
}
If this is not you want, you can refer to the scss
file under /src/style
to configure your own theme.
Plugin
You can implement your own plugins according to the src/plugin/temp.js
, such as an async loading data plugin.
Don't forget to register the plugin after complete.
import FlexTable from '@qmhc/flex-table'
import myPlugin from 'my-plugin'
FlexTable.registerPlugin(name, myPlugin)
You can also replace one plugin with replacePlugin
method.
License
MIT