npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-table-cell-selector

v0.6.0

Published

JS library allows you to select cells of HTML tables as well as cleaning, copying, cutting and pasting

Downloads

125

Readme

JS Table Cell Selector

Build Status

JS library allows you to select cells of HTML tables as well as cleaning, copying, cutting and pasting data of table.

Supported copy/cut/paste to spreadsheets such as Microsoft Excel, Google Docs, LibreOffice and OpenOffice.

Demo

See demo.

Setup

Classic web with <script> tag

Include the js-files which you can find in the dist folder.

<script src="dist/tcs.bundle.min.js"></script>

ES6

Install module using npm:

npm install js-table-cell-selector

or using yarn:

yarn add js-table-cell-selector

and import:

import TableCellSelector from "js-table-cell-selector";

Usage example

var table = document.getElementById("tcs-table");
var options = {deselectOutTableClick: false, enableChanging: true};
var buffer = new TableCellSelector.Buffer();
var tcs = new TableCellSelector(table, options, buffer);
tcs.onStartSelect = function (event, cell) {
    console.log("start select");
};
tcs.enableHotkeys = true;

Keyboard shortcuts

  • Ctrl + A — select all
  • Ctrl + C — copy
  • Ctrl + V — paste
  • Ctrl + X — cut
  • Ctrl + (Backspace or Delete) — clear

Note: operations for the browser buffer only work when TableCellSelector.Buffer is initialized.

Options

| Name | Type | Default | Description | |-------------------------|------------------|---------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------| | deselectOutTableClick | Bool | true | Deselect when clicking is outside the table | | enableChanging | Bool | false | The flag allows changing the table using key combinations | | enableHotkeys | Bool | true | The flag of hotkeys enable | | getCellFn | Function | function (cell, coord) { return cell.innerText; } | Getting cell value | | ignoreClass | String | 'tcs-ignore' | You can add this class to a TR or TD | | ignoreTfoot | Bool | false | Ignore tag TFOOT and its contents | | ignoreThead | Bool | false | Ignore tag THEAD and its contents | | mergePastingGlue | String | ' ' | The gluing string when pasted into merged cells | | mouseBlockSelection | Bool | true | Must be disabled when editing cell contents when contenteditable is true for selection to work | | selectClass | String | 'tcs-select' | Class added to the cell when selecting | | selectIgnoreClass | Bool | true | Select ignored cells. The actions of changing them will not work anyway | | setCellFn | Function | function (cell, data, coord) { cell.innerText = data; } | Setting cell value | | tableClass | String | 'tcs' | Class added to the table when initializing |

Methods:

The readout of positions is from the upper left corner of the table as [y, x]

constructor (table [, options [, buffer]])

clear ([c1 [, c2]])

Clear selected cell

@param c1 - starting position [0, 0]
@param c2 - end position [1, 1]
@returns {boolean}

copy ([c1 [, c2]])

Copy with browser buffer support

@param c1 - starting position [0, 0]
@param c2 - end position [1, 1]
@returns {array[][] | false}

cut ([c1 [, c2]])

Cut with browser buffer support

@param c1 - starting position [0, 0]
@param c2 - end position [1, 1]
@returns {array[][] | false}

deselect ()

Remove selection

@returns {number}

getCoords ()

Get selection coordinates

@returns {array[][] | false}

initSizeMatrix ()

initialize or re-initialize the size matrix

paste (data [, c1 [, c2]])

@param data - array[][]
@param c1 - starting position [0, 0]
@param c2 - end position [1, 1]

select (c1 [, c2])

@param c1 - starting position [0, 0]
@param c2 - end position [1, 1]
@returns {boolean}

selectAll()

Select all cells

@returns {number}

destroy ()

Events:

onStartSelect(event, cell)

Occurs at the starting of a selection

onSelect(prevState, cell, coord)

Occurs when a new cell is selected, starting from the second cell (triggered on each cell in the selection). The first is triggered onStartSelect

prevState - flag that is true if the cell has already been selected otherwise false

onDeselect(event, cell)

Occurs when deselecting a cell

onFinishSelect(event)

Occurs at the finishing of a selection

License

Apache 2.0