1.0.0 • Published 5 years ago

htmltables v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

HTML Tables

Allows you to manipulate HTML tables using JS.

Usage

  • Install this module using npm i htmltables --save or yarn add htmltables
  • Require it using import Table from 'html-tables' or const Table = require('htmltables')
  • Create a new table using const table = new Table(document.getElementById('my-table'))

PS: This would remove existing table contents

Available Calls

Method nameFunctionArguments
addRow(index)adds a row to tableindex (optional) - adds a row BEFORE this index
removeRow(index)removes a row at specified indexindex (required) - removes a row at index given
set(row, col, data)Sets data to given row and col id. The row must exist. The col would be created automaticallyrow (required) - index of row col (required) - index of column (a new column, i.e. a td would be created if not present) data (required) - text data to go in that column
get(row, col)Gets data at specified row and col indexrow (required) - index of row col (required) - index of col
getRow(rowIndex)Gets array of text nodes present in that rowrowIndex (required) - index of row
getColumn(colIndex)Gets array of text nodes present in that columncolIndex (required) - index of column

Example

<table id="my-table"></table>
const table = new Table(document.getElementById('my-table'))

table.addRow()
table.addRow()
table.addRow()
table.addRow()
table.addRow()

for(let i=0;i<5;i++) {
	for(let j=0;j<4;j++) {
		table.set(i,j, `${i} * ${j} = ${i * j}`)
	}
}

console.log(table.getRow(0))
console.log(table.getColumn(0))