• Stars
    star
    349
  • Rank 121,528 (Top 3 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated 21 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A regular <table> library, for async and virtual data models.

regular-table

FINOS active badge NPM Version NPM Version Build Status

A Javascript library for the browser, regular-table exports a custom element named <regular-table>, which renders a regular HTML <table> to a sticky position within a scollable viewport. Only visible cells are rendered and queried from a natively async virtual data model, making regular-table ideal for enormous or remote data sets. Use it to build Data Grids, Spreadsheets, Pivot Tables, File Trees, or anytime you need:

  • Just a regular <table>.
  • Virtually rendered for high-performance.
  • async data model handles slow, remote, enormous, and/or distributed backends.
  • Easy to style, works with any regular CSS for <table>.
  • Small bundle size, no dependencies.

Examples


Documentation

What follows functions as a quick-start guide, and will explain the basics of the Virtual Data Models, Styling and Interaction APIs. Complete API docs and documented examples are also available.

Installation

Include via a CDN like JSDelivr:

<script src="https://cdn.jsdelivr.net/npm/regular-table"></script>
<link
    rel="stylesheet"
    href="https://cdn.jsdelivr.net/npm/regular-table/dist/css/material.css"
/>

Or, add to your project via yarn:

yarn add regular-table

... then import into your asset bundle.

import "regular-table";
import "regular-table/dist/css/material.css";

<regular-table> Custom Element

regular-table exports no symbols, only the <regular-table> Custom Element which is registered as a module import side-effect. Once loaded, <regular-table> can be used just like any other HTMLElement, using regular browser APIs:

const regularTable = document.createElement("regular-table");
document.body.appendChild(regularTable);

... or from regular HTML:

<regular-table></regular-table>

... or from your library of choice, as long as it supports regular HTML! Here's an example for React/JSX:

const App = () => <regular-table></regular-table>;
ReactDOM.render(<App />, document.getElementById("root"));

.setDataListener() Virtual Data Model

Let's start with with a simple data model, a two dimensional Array. This one is very small at 3 columns x 6 rows, but even for very small data sets, regular-table won't read your entire dataset at once. Instead, we'll need to write a simple virtual data model to access DATA and COLUMN_NAMES indirectly.

const DATA = [
    [0, 1, 2, 3, 4, 5],
    ["A", "B", "C", "D", "E", "F"],
    [true, false, true, false, true, false],
];

When clipped by the scrollable viewport, you may end up with a <table> of just a rectangular region of DATA, rather than the entire set. A simple viewport 2x2 may yield this <table>:

0 A
1 B
{
    "num_rows": 26,
    "num_columns": 3,
    "data": [
        [0, 1],
        ["A", "B"]
    ]
}

Here's a an implementation for this simple virtual data model, the function getDataSlice(). This function is called by your <regular-table> whenever it needs more data, with coordinate arguments, (x0, y0) to (x1, y1). Only this region is needed to render the viewport, so getDataSlice() returns this rectangular slice of DATA. For the window (0, 0) to (2, 2), getDataSlice() would generate an Object as above, containing the data slice, as well as the overall dimensions of DATA itself ( num_rows, num_columns), for sizing the scroll area. To render this virtual data model to a regular HTML <table>, register this data model via the setDataListener() method:

function getDataSlice(x0, y0, x1, y1) {
    return {
        num_rows: (num_rows = DATA[0].length),
        num_columns: DATA.length,
        data: DATA.slice(x0, x1).map((col) => col.slice(y0, y1)),
    };
}

regularTable.setDataListener(getDataSlice);

This will render your regular HTML <table> ! Your DOM will look something like this, depending on the size of your viewport. Notice there are fewer rows and columns in the resulting HTML, e.g. the column Column 3 (boolean) - as you scroll, more data will be fetched from getDataSlice(), and parts of the <table> will redrawn or extended as needed.

<regular-table>
    <table>
        <tbody>
            <tr>
                <td>0</td>
                <td>A</td>
            </tr>
            <tr>
                <td>1</td>
                <td>B</td>
            </tr>
        </tbody>
    </table>
</regular-table>

virtual_mode Option

regular-table supports four modes of virtual scrolling, which can be configured via the virtual_mode optional argument. Note that using a virtual_mode other than the default "both" will render the entire <table> along the non-virtual axis(es), and may cause rendering performance degradation.

  • "both" (default) virtualizes scrolling on both axes.
  • "vertical" only virtualizes vertical (y) scrolling.
  • "horizontal" only virtualizes horizontal (x) scrolling.
  • "none" disable all scroll virtualization.
table.setDataListener(listener, { virtual_mode: "vertical" });

Column and Row Headers

regular-table can also generate Hierarchial Row and Column Headers, using <th> elements which layout in a fixed position within the virtual table. It can generate Column Headers (within the <thead>), or Row Headers (the first children of each tbody tr), via the column_headers and row_headers properties (respectively) of your data model's Response object. This can be renderered with column_headers, a two dimensional Array which must be of length x1 - x0, one Array for every column in your data window.

Column 1 (number) Column 2 (string)
0 A
1 B
{
    "num_rows": 26,
    "num_columns": 3,
    "data": [
        [0, 1],
        ["A", "B"]
    ],
    "column_headers": [["Column 1 (number)"], ["Column 2 (string)"]]
}

Hierarchial/Group Headers

regular-table supports multiple <tr> of <th>, and also uses colspan and rowspan to merge simple consecutive names, which allows description of simple Row and Column Group Hierarchies such as this:

Colgroup 1
Column 1 Column 2
Rowgroup 1 Row 1 0 A
Row 2 1 B
{
    "num_rows": 26,
    "num_columns": 3,
    "data": [
        [0, 1],
        ["A", "B"]
    ],
    "row_headers": [
        ["Rowgroup 1", "Row 1"],
        ["Rowgroup 1", "Row 2"]
    ],
    "column_headers": [
        ["Colgroup 1", "Column 1"],
        ["Colgroup 1", "Column 2"]
    ]
}

Note that in the rendered HTML, for these Row and Column Array, repeated elements in a sequence will be automatically merged via rowspan and colspan attributes. In this example, e.g. "Rowgroup 1" will only output to one <th> node in the resulting <table>.

metadata Data-Aware Styling

A dataListener may also optionally provide a metadata field in its response, a two dimensional Array of the same dimensions as data. The values in this field will accompany the metadata records returned by regular-table's getMeta() method (as described in the next section).

{
    "num_rows": 26,
    "num_columns": 3,
    "data": [
        [-1, 1],
        ["A", "B"]
    ],
    "metadata": [
        ["pos", "neg"],
        ["green", "red"]
    ]
}

async Data Models

With an async data model, it's easy to serve getDataSlice() remotely from node.js or re-implement the JSON response protocol in any language. Just return a Promise() from, or use an async function as an argument to, setDataListener(). Your <regular-table> won't render until the Promise is resolved, nor will it call your data model function again until the current call is resolved or rejected. The following async example uses a Web Worker, but the same principle applies to Web Sockets, readFile() or any other asynchronous source. Returning a Promise blocks rendering until the Web Worker replies:

// Browser

let callback;

worker.addEventListener("message", (event) => {
    callback(event.data);
});

regularTable.setDataListener((...viewport) => {
    return new Promise(function (resolve) {
        callback = resolve;
        worker.postMessage(viewport);
    });
});
// Web Worker

self.addEventListener("message", async (event) => {
    const response = await getDataSlice.apply(null, event.data);
    self.postMessage(response);
});

.addStyleListener() and getMeta() Styling

regular-table can be styled trivially with just regular CSS for <table>.

// Zebra striping!
regular-table tr:nth-child(even) td {
    background: rgba(0, 0, 0, 0.2);
}

However, CSS alone cannot select on properties of your data - if you scroll this example, the 2nd row will always be the striped one. Some other data-reliant style examples include:

  • Styling a specific column in the virtual data set, as <td> may represent a different column based on horizontal scroll position.
  • Styling cells by value, +/-, heatmaps, categories, etc.
  • Styling cells based on data within-or-outside of the virtual viewport, grouping depth, grouping categories, etc.

To make CSS that is virtual-data-model-aware, you'll need to use addStyleListener(), which invokes a callback whenever the <table> is re-rendered, such as through API invocations of draw() and user-initiated events such as scrolling. Within this optionally async callback, you can select <td>, <th>, etc. elements via regular DOM API methods like querySelectorAll().

// Only select row_headers!
table.addStyleListener(() => {
    for (const th of table.querySelectorAll("tbody th")) {
        style_th(th);
    }
});

Once you've selected the <td> and <th> you want to paint, getMeta() will return a MetaData record of information about the HTMLElement's virtual position. This example uses meta.x, the position in data-space, to make virtual-scroll-aware zebra striping.

function style_th(th) {
    const meta = table.getMeta(th);
    th.classList.toggle("zebra-striped", meta.x % 2 === 0);
}
.zebra-striped {
    background-color: rgba(0, 0, 0, 0.2);
}

.invalidate()

To prevent DOM renders, <regular-table> conserves DOM calls like offsetWidth to an internal cache. When a <td> or <th>'s width is modified within a callback to .addStyleListener(), you must indicate to <regular-table> that its dimensions have changed in order to invalidate this cache, or you may not end up with enough rendered columns to fill the screen!

A call to invalidate() that does not need new columns only imparts a small runtime overhead to re-calculate virtual width per async draw iteration, but should be used conservatively if possible. Calling invalidate() outside of a callback to .addStyleListener() will throw an Error.

table.addStyleListener(() => {
    for (const th of table.querySelectorAll("tbody th")) {
        th.style.maxWidth = "20px";
    }
    table.invalidate();
});

.addEventListener() Interaction

<regular-table> is a normal HTMLElement! Use the regular-table API in concert with regular DOM API methods that work on other HTMLElement to create advanced functionality, such as this example of virtual row select:

const selected_rows = [];

table.addEventListener("mousedown", (event) => {
    const meta = table.getMeta(event.target);
    if (meta && meta.y >= 0) {
        selected_rows.push(meta.y);
        table.draw();
    }
});

table.addStyleListener(() => {
    for (const td of table.querySelectorAll("td")) {
        const meta = table.getMeta(td);
        td.classList.toggle("row-selected", selected_rows.includes(meta.y));
    }
});

Advanced examples can be found in the examples directory, and in the bl.ocks example gallery.

Scrolling

Because of the structure of the HTML <table> element, <td> elements must be aligned with their respective row/column, which causes default <regular-table> to only be able to scroll in increments of a cell, which can be irregular when column data is of different lengths. Optionally, you may implement sub-cell scrolling in CSS via <regular-table> slotted CSS variables. The provided material.css theme does exactly this, or you can implement this in any custom style by importing the sub_cell_scrollling.css stylesheet explicitly:

<link
    rel="stylesheet"
    href="https://cdn.jsdelivr.net/npm/regular-table/dist/css/sub-cell-scrolling.css"
/>

Pivots, Filters, Sorts, and Column Expressions with perspective

regular-table is natively compatible with perspective, a WebAssembly streaming visualization engine. By using a perspective.Table as a Virtual Data Nodel, it becomes simple to achieve user-driven row and column pivots, filters, sorts, and column expressions, as well as charts and persistent layouts, from high-frequency updating data.

Development

First install dev_dependencies:

yarn

Build the library

yarn build

Run the test suite

yarn test

Start the example server at http://localhost:8080/examples/

yarn start

OpenSSF

The Regular Table project achieves the "Passing" Open Source Security Foundation (OpenSSF) Best Practices status.

License

This software is licensed under the Apache 2.0 license. See the LICENSE and AUTHORS files for details.

More Repositories

1

perspective

A data visualization and analytics component, especially well-suited for large and/or streaming datasets.
C++
8,439
star
2

legend

The Legend project
HTML
856
star
3

jupyterlab_templates

Support for jupyter notebook templates in jupyterlab
Python
395
star
4

plexus-interop

Plexus Interop open source project hosted by the Fintech Open Source Foundation
C#
253
star
5

FDC3

An open standard for the financial desktop.
HTML
193
star
6

waltz

Enterprise Information Service
Java
178
star
7

OpenMAMA

OpenMAMA is an open source project that provides a high performance middleware agnostic messaging API that interfaces with a variety of proprietary and open source message oriented middleware systems.
C++
144
star
8

datahelix

The DataHelix generator allows you to quickly create data, based on a JSON profile that defines fields and the relationships between them, for the purpose of testing and validation
Java
141
star
9

morphir

A universal language for business and technology
Elm
140
star
10

compliant-financial-infrastructure

Compliant Financial Infrastructure accelerates the development, deployment and adoption of cloud services in a way that adheres to common security and regulatory controls.
128
star
11

OSLC-handbook

A data store and handbook of practical information about complying with the most common open source licenses.
HTML
127
star
12

common-domain-model

The CDM is a model for financial products, trades in those products, and the lifecycle events of those trades. It is an open source standard that aligns data, systems and processes and is available as code in multiple languages for easy implementation across technologies.
Java
121
star
13

TimeBase-CE

High performance time series database
Java
110
star
14

ipyregulartable

High performance, editable, stylable datagrids in jupyter and jupyterlab
JavaScript
109
star
15

git-proxy

Deploy custom push protections and policies on top of Git
JavaScript
94
star
16

legend-studio

Legend Studio
TypeScript
87
star
17

datahub

DataHub - Synthetic data library
Python
80
star
18

SymphonyElectron

A desktop client for the Symphony Collaboration Platform built using Electron
TypeScript
80
star
19

legend-engine

Legend Engine module
Java
79
star
20

legend-pure

Legend Pure module
Java
66
star
21

community

FINOS Community, Project and SIG wide collaboration space
JavaScript
63
star
22

spring-bot

Spring Boot + Java Integration for Symphony/Teams Chat Platform Bots and Apps
Java
59
star
23

devops-automation

Provide a continuous compliance and assurance approach to DevOps that mutually benefits banks, auditors and regulators whilst accelerating DevOps adoption in engineering and fintech IT departments.
JavaScript
58
star
24

htc-grid

Python
55
star
25

SymphonyMediaBridge

The Symphony Media Bridge (SMB) is a media server application that handles audio, video and screen sharing media streams in an RTC conference system.
C++
55
star
26

CatchIT

Source code secret scanner
Python
51
star
27

open-developer-platform

Delivering open source software development best practices while enforcing security and legal compliance for the financial services industry .
Shell
50
star
28

traderX

TypeScript
48
star
29

openfin-react-hooks

A collection of React Hooks built on top of the Openfin API - from Scott Logic
TypeScript
48
star
30

cla-bot

cla-bot is a GitHub bot for automation of Contributor Licence Agreements (CLAs).
JavaScript
45
star
31

morphir-elm

Tools to work with the Morphir IR in Elm.
Elm
44
star
32

kdb

kdb+ Working Group from FINOS Data Technologies program
q
43
star
33

architecture-as-code

"Architecture as Code" (AasC) aims to devise and manage software architecture via a machine readable and version-controlled codebase, fostering a robust understanding, efficient development, and seamless maintenance of complex software architectures
TypeScript
43
star
34

tracdap

A next-generation data and analytics platform for use in highly regulated environments
Java
40
star
35

vuu

Vuu - an open source view server and html 5 based UI system
TypeScript
40
star
36

a11y-theme-builder

DesignOps toolchain theme builder for accessibility inclusion using Atomic Design.
TypeScript
40
star
37

financial-objects

FINOS Financial Objects Program Documentation
JavaScript
39
star
38

legend-sdlc

Legend SDLC module
Java
39
star
39

open-source-readiness

Accelerate financial services firms’ journeys toward open source readiness, by advancing the readiness of participants’ firms and informing guidance for the broader industry in the form of white papers, presentations, and blog posts.
JavaScript
35
star
40

FDC3-Sail

Open implementation of the FDC3 standard using Electron and an integrated App Directory.
TypeScript
34
star
41

open-regtech-sig

The FINOS Regulation Innovation Special Interest Group (SIG) is a community of people interested in creating open source solutions for regulatory and compliance issues in financial services.
32
star
42

symphony-bdk-python

Symphony Python Bot Development Kit (BDK)
Python
31
star
43

greenkey-asrtoolkit

A collection of useful tools for handling speech recognition data
Python
30
star
44

finos-landscape

FINOS Project Landscape
Shell
29
star
45

software-project-blueprint

Project blueprint for Fintech Open Source Foundation hosted projects.
JavaScript
28
star
46

morphir-examples

Elm
27
star
47

InnerSource

The FINOS InnerSource SIG is a community of people implementing, or interested in implementing, InnerSource within their financial services organization.
JavaScript
27
star
48

common-cloud-controls

FINOS Common Cloud Controls
Gherkin
26
star
49

secref-data

Security Reference Data project
JavaScript
25
star
50

rune-dsl

The project containing the Rune DSL grammar and default code generators
Java
25
star
51

voice-metadata-standard

This is a project from FINOS Voice program to define a standard for call metadata.
25
star
52

JCurl

JSON-aware curl (1) in Java
Java
24
star
53

symphony-bdk-java

The Symphony BDK (Bot Developer Kit) for Java helps you to create production-grade Chat Bots and Extension Applications on top of the Symphony REST APIs.
Java
23
star
54

zenith

Create a space where expertise can be identified and implemented to help the fintech ecosystem understand and adopt new technologies through the exploration and creation of common understanding.
HTML
22
star
55

fdc3-desktop-agent

Chrome Extension implementation of an FDC3 Desktop Agent
TypeScript
22
star
56

ai-readiness

Our goal is to mutually develop a governance framework that manages the on-boarding, development of, and running AI-based solutions within financial services organisations - allowing us all to unlock the potential of this disruptive technology in a safe, trustworthy and compliant way.
21
star
57

morphir-jvm

Tools to work with the Morphir IR on/using the JVM.
Scala
21
star
58

legend-shared

Legend Shared module
Java
21
star
59

glue

Glue is an enterprise data model for the buy side, tailored for Wealth and Asset Managers and covering key entities such as Party, Business Relationship, Investment Strategy, Instruments, Portfolios and more.
JavaScript
21
star
60

symphony-api-spec

Swagger definitions for Symphony LLC public REST API
Shell
19
star
61

exodus

Migration tools for Tabular Data to Oracle JSON/Tabular Data
Scheme
18
star
62

greenkey-discovery-sdk

Speed up business workflows through custom 'voice skills' and text (NLP) interpreters
Python
14
star
63

DEI-SIG

JavaScript
13
star
64

reference-foss-policy

Reference FOSS Policy for Financial Services Institutions
13
star
65

morphir-scala

Scala
12
star
66

branding

FINOS (Fintech Open Source Foundation) official branding resources
12
star
67

FDC3-conformance-framework

A framework for testing whether desktop containers implement the FDC3 standard
TypeScript
12
star
68

metadata-tool

A command line tool for performing various tasks with Fintech Open Source Foundation (FINOS) metadata.
Clojure
12
star
69

morphir-dotnet

F#
12
star
70

finos.github.io

The source for the FINOS Project catalog
JavaScript
11
star
71

secure-electron-adapter

JavaScript
11
star
72

open-reg-tech-us-lcr

Open Reg Tech: US LCR
Elm
11
star
73

messageml-utils

MessageML is a markup language used by the Symphony Agent API for representing messages, including formatting (bold, italic, numbered and unnumbered lists etc.) and entity data representing structured objects.
Java
11
star
74

generator-symphony

Yeoman based generator for Symphony Bots and Applications
JavaScript
10
star
75

fdc3-dotnet

.NET Standard FDC3 declarations to implement concrete FDC3 compatible .NET desktop agents
C#
10
star
76

bot-github-chatops

A Symphony bot that uses ChatOps techniques to allow a firm employee to interact in a compliant manner with GitHub issues and PRs
Clojure
10
star
77

code-scanning

How to protect FINOS hosted projects from security threats and license compliance issues
Python
8
star
78

legend-community-delta

Combining best of open data standards with open source technologies
Jupyter Notebook
8
star
79

legend-depot

Legend Depot component
Java
8
star
80

openfin-python-adapter

Hadouken python language adapter.
Python
7
star
81

calendar

FINOS Calendar
JavaScript
7
star
82

finos-parent-pom

A Maven Parent POM that provide common build and release features using the Symphony Software Foundation Infrastructure
7
star
83

backplane

FDC3 Desktop Agent Bridge
C#
6
star
84

osr-checklists

Checklists for key components and processes of open source programs
6
star
85

morphir-service

HTML
5
star
86

SwiftSearch

SwiftSearch is a plugin for SymphonyElectron
TypeScript
5
star
87

technical-oversight-committee

📋 FINOS Technical Oversight Committee
5
star
88

ScreenSnippet

Screen snippet utility for Windows.
C#
4
star
89

OpenMAMA-testdata

OpenMAMA Test Data
Batchfile
4
star
90

pylegend

pylegend
Python
4
star
91

certificate-toolbox

A collection of command-line tools to generate PKI Signing Certificates and X.509 Identity Certificates
Shell
4
star
92

cdm-object-builder

Object Builder
TypeScript
4
star
93

FDC3-Archive

3
star
94

curref-data

3
star
95

greenkey-intercom-sdk

Voice-enable your front-end apps with instant intercoms
JavaScript
3
star
96

symphony-wdk

Symphony Workflow Developer Kit (WDK), a bot capable of running workflows
Java
3
star
97

a11y-theme-builder-sdk

Collection of atomic design services for computing WCAG compliant code artifacts.
TypeScript
3
star
98

sea-quick-start

Quick start demo project for the Secure Electron Adapter
JavaScript
3
star
99

rune-common

Java
3
star
100

legend-juju-bundle

Juju bundle for all the FINOS Legend Charmed K8s Operators
Python
2
star