Table guide
This package can be installed in every node project as well as react-native-cli and expo-cli.
The simple project comes from a personal need. Hope this will be useful!
This package allows you to use simple tables easily.
Installation
It's very easy to download, just run the following command:
npm install node_tables
Simple demo (javascript)
The javascript code is very simple, first you need to import the package by using:
import Tables from "node_tables";
Then create the object Table:
let table = new Table(arg1,arg2,arg3,arg4,arg5);
Below there is the full table where you can understand the function of the five arguments.
Name Function arg1 Number of rows arg2 Number of columns arg3 It's a boolean variable that allows you to use labels for columns and rows. arg4 If the third argument is true, you have to pass the array of labels (row names) arg5 If the third argument is true, you have to pass the array of labels (columns names)
Tip
You will be able to point to a cell by passing the row number, and the column number or simply by the row's name,and the column's name.
Then, create the 2D array of data:
const values = [
[64,59,56,51], [65, 60, 61, 55], [67,65,62,63], [67,65.6,62.7,63], [67,65,'k',63],
]
Now you can fill the table by passing the previous 2D array (this is an async function).
table.fill(values).then(() => {table.print(); console.log('The value selected is: ',table.getValue(1, 1))});
Warning
The indexes (row and column) start from 1 and not from 0 as usual in arrays (this way should be easier to read).
All the methods
Down below there the full table that shows you all the available methods.
Name | Function |
---|---|
fill(array) | Fill the table by passing the 2D data array. |
getCell(row, column) | It returns the cell object at those indexes (you can also pass the row's name or the column's name). |
getValue(row, column) | It returns the cell value at those indexes (you can also pass the row's name or the column's name). |
set(val, row, column) | It overrides the value of a cell with a new one (you can also pass the row's name or the column's name). |
indexOf(val, allowStringConversion) | It returns an array containing all the row indexes and column indexes when it finds your value. In order to be able to search for an integer by passing a string with the same value (or the other way around) you have to pass a boolean as the second argument. |
print() | It is used mainly for debug and it prints the table in the console. |
Contact me
If you have any questions or suggestions please contact me at: francesco.podesta03@gmail.com