0.0.3 • Published 7 years ago

we-table v0.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

weTable

A table builder which is able to graft row from row

Usage

Install

yarn add we-table or npm install we-table

Usage

import {
    Table,
    Row,
    Cell
} from 'we-table'

const table = new Table()

const priceName = new Row().addCell([new Cell("票价名称", 2, 3), new Cell("三楼200元"), new Cell("内场280元")])
const price = new Row().addCell([new Cell("1440元"), new Cell("720元")])
const priceAmount = new Row().addCell([new Cell("票价", 1, 3), new Cell(144000), new Cell(72000)])
const priceNumber = new Row().addCell([new Cell("可售张数", 1, 3), new Cell(9), new Cell(9)])
const priceRate = new Row().addCell([new Cell("已售比例", 1, 3), new Cell(0.5), new Cell(0.5)])

const firstRow = new Row()
            .addCell(new Cell("销售渠道", 5, 3))
            .appendRow(priceName)
            .addCell(new Cell("总计", 5))
// or:
// const firstRow = priceName.unshiftCell(new Cell("销售渠道", 5, 3)).addCell(new Cell("总计", 5))

table.addRow([firstRow, price, priceAmount, priceNumber, priceRate])

console.log(table.render())

Output

<table><tr><td rowspan="5" colspan="3" class="row-5 col-3">销售渠道</td><td rowspan="2" colspan="3" class="row-2 col-3">票价名称</td><td >三楼200元</td><td >内场280元</td><td rowspan="5" class="row-5">总计</td></tr><tr><td >1440元</td><td >720元</td></tr><tr><td colspan="3" class="col-3">票价</td><td >144000</td><td >72000</td></tr><tr><td colspan="3" class="col-3">可售张数</td><td >9</td><td >9</td></tr><tr><td colspan="3" class="col-3">已售比例</td><td >0.5</td><td >0.5</td></tr></table>

API reference

Modules

Classes

weTable

weTable: A table builder which is able to graft row from row

Cell

Cell: Table Cell (td)

Kind: global class

new Cell(content, row, col)

create a Cell instance

ParamTypeDefaultDescription
contentStringcontent to display
rowNumber1rowspan value
colNumber1colspan value

cell.setSpan(row, col)

set rowspan and colspan

Kind: instance method of Cell

ParamTypeDefaultDescription
rowNumber1rowspan value
colNumber1colspan value

cell.setClass(className)

set class name

Kind: instance method of Cell

ParamTypeDescription
classNameStringclass name

cell.render() ⇒ String

render td element str

Kind: instance method of Cell

Row

Row: Table Row (tr)

Kind: global class

new Row(cells)

create a Row instance

ParamTypeDescription
cellsArray | Objectcell instance

row.addCell(cells)

append cell(s) in the back of cells stack (push)

Kind: instance method of Row

ParamTypeDescription
cellsArray | Objectcell instance

row.unshiftCell(cells)

insert cell(s) in the front of cells stack (unshift)

Kind: instance method of Row

ParamTypeDescription
cellsArray | Objectcell instance

row.appendRow(row)

graft row cells in the back of cells stack

Kind: instance method of Row

ParamTypeDescription
rowRowrow instance

row.setClass(className)

set class name

Kind: instance method of Row

ParamTypeDescription
classNameStringclass name

row.render() ⇒ String

render tr element str

Kind: instance method of Row

Table

Table: HTML Table (table)

Kind: global class

new Table(rows)

create a Table instance

ParamTypeDescription
rowsArray | Objectrow instance

table.addRow(rows)

append row(s) in the back of rows stack (push)

Kind: instance method of Table

ParamTypeDescription
rowsArray | Objectrow instance

table.unshiftRow(rows)

insert row(s) in the front of rows stack (unshift)

Kind: instance method of Table

ParamTypeDescription
rowsArray | Objectrow instance

table.setClass(className)

set class name

Kind: instance method of Table

ParamTypeDescription
classNameStringclass name

table.render() ⇒ String

render table element str

Kind: instance method of Table

docs autogenerated via jsdoc2md