0.1.25 β€’ Published 9 months ago

@borderliner/canvas-table v0.1.25

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@borderliner/canvas-table

English | δΈ­ζ–‡

⚑ High-performance canvas table that display mass of data for web. Fork of: x-canvas-table, upgraded to ES module and latest dependencies.

14.7kb gizped, no dependency!

80 columns & 100,000 rows data:

100000*80

Feature

  • High performance works on canvas. πŸš€
  • Event support, such as click, mouseenter, mouseleave, etc. ✨
  • Custom style config. πŸ’„
  • Custom icon support. πŸ‘
  • Tooltip for every component. πŸ”Ž
  • Write with typescript. πŸ‘”
  • You can even create your own component to display! πŸ’–

! it's just like a table implement on dom!

Examples

  • basic usage: demo
  • display 100000 records: demo
  • load remote data with scroll: demo
  • fixed header (setting by default, can't change yet)
  • fixed columns: demo
  • grouping table head: demo
  • custom style: demo
  • render icon component: demo

Usage

import

  1. use pnpm
pnpm i @borderliner/canvas-table
  1. use cdn
<script src="https://unpkg.com/@borderliner/canvas-table/umd/canvastable.min.js"></script>

basic usage

<div id="canvas-table"></div>
import CanvasTable from "@borderliner/canvas-table";

const columns = [
  {title: 'avatar', dataIndex: 'avatar'},
  {title: 'name',dataIndex: 'name'},
  {title: 'age', dataIndex: 'age'},
  {title: 'address', dataIndex: 'address'}
]
const dataSource = [
  {avatar: 'πŸŽ…πŸ»',name: 'chuanJianGuo', age: 74, address: 'America'},
  {avatar: 'πŸ‘΅πŸ»', name: 'caiEnglish', age: 63, address: 'China Taiwan'},
  {avatar: '-',name: 'trump', age: 74, address: 'America'},
  {avatar: '-',name: 'johnson', age: 70, address: 'England'}
]
const ct = new CanvasTable({
  container: document.getElementById('canvas-table'),
  columns: columns,
  style: { height: 500, width: '100%' }
})

ct.source = dataSource;

result: basic usage

online demo: click

API

CanvasTable

PropertyDescriptionTypeDefault
containerContainer element for tableHTMLElement-
columnsColumns of tableIColumnProps[]-
sourceData record array to be displayedobject[]-
styleStyle for tableITableStylePropssee ITableStyleProps
onScrollLoadCallback executed when table scroll to bottom(scrollLoadHeight)() => Promise<any>-
scrollLoadHeightdistance to trigger onScrollLoadnumber150
onRowSet event props on per rowITableEventHandler-

IColumnProps

One of the Table columns prop for describing the table's columns.

PropertyDescriptionTypeDefault
dataIndexDisplay field of the data recordobject[]-
titleTitle of this columnstring-
alignThe specify which way that column is aligned'left'|'right' | 'center''left'
popTitletooltip for table header cellstring-
widthWidth of this columnnumber150
childrenGroup table headIColumn[]-
fixedSet column to be fixed'left' | 'right'-
rendercustom render(value, record) => string | Layer-
onCellSet event props on per cellITableEventHandler-

ITableStyleProps

You can custom your table style use this prop

PropertyDescriptionTypeDefault
widthwidth of tablenumber | string100%
heightheight of tablenumber | string100%
rowHeightheight of each rownumber55
columnWidthdefault width of all columnsnumber150
borderColorcolor of borderstring'#e8e8e8'
textColorcolor of textstring'rgba(0,0,0,0.65)'
fontSizefont sizestring14px
fontFamilyfont familystring-
paddingboth left and right padding of table cellnumber16
headerBackColorbackground color of header cellstring'#fafafa'
headerRowHeightheight of header cellnumber55

onRow usage

Event binding, same as onRow and onCell

interface ITableEventHandler {
    (record: object, rowIndex: number): {
        onClick?: (event) => void,       // onClick Event
        onDoubleClick?: (event) => void, // Double Click
        onContextMenu?: (event) => void, // Right click Event
        onMouseEnter?: (event) => void,  // Mouse Enter
        onMouseLeave?: (event) => void,  // Mouse Leave
    }
}
// Example:
new CanvasTable({
    onRow: (record, rowIndex) => {
        onClick: () => { alert(`${rowIndex} row clicked`) }
    }
})

Layer Component

it's the basic component in canvas table. you can think it as a div in HTML, it usually used on render property of IColumn interface. you can use it to build a complex component to render.

let's see what we can do.

PropertyDescriptionTypeDefault
stylestyle of layerILayerStyleProps-
eventevent on layerIEventCollection-
popTitleset title attribute a canvas elementstring-
childrenchildren of layerLayer[]-

ILayerStyleProps

if you know css, you will know how to use it immediately.

interface ILayerStyleProps {
  top?: number // assume it's top attribute and when position: absolute
  left?: number // assume it's left attribute and when position: absolute
  width?: number | string // number for px, string for percentage of parent
  height?: number | string  // number for px, string for percentage of parent
  padding?: number | number[]  // same as css
  color?: string               // same as css
  backgroundColor?: string;    // same as css
  border?: string | string[]   // same as css
  fontFamily?: string          // same as css
  fontSize?: string            // same as css
  fontWeight?: 'normal' | 'bold' 
  zIndex?: number              // same as css
  align?: 'left' | 'center' | 'right'
  overflow?: 'hidden' | 'ellipsis'
}

example creating complex render: demo

the following components is all derived from Layer.

Render A Icon Component

it's provide a Svg Component to support rendering svg file,

How to use?

step 1: import svg file && Svg component

import Home from '@/assets/svg/home.svg'
const { Svg } = CanvasTable

step 2: use render property in columns

const columns = [
  {
    title: 'Action',
    render: () => {
      return new Svg({
        popTitle: 'click me',
        path: Home,
        style: {width: 30, height: 30, color: '#1890ff'},
        event: {
          onClick: () => {alert('button click')}
        }
      })
    }
  }
]

full example: demo

Text Component

PropertyDescriptionTypeDefault
texttext to showstring-
0.1.25

9 months ago

0.1.24

9 months ago

0.0.22

11 months ago

0.0.21

11 months ago

0.0.20

12 months ago

0.0.19

12 months ago

0.0.18

12 months ago

0.0.17

12 months ago

0.0.16

12 months ago

0.0.15

12 months ago

0.0.14

12 months ago

0.0.13

12 months ago

0.0.12

12 months ago

0.0.11

12 months ago

0.0.10

12 months ago

0.0.9

12 months ago

0.0.8

12 months ago