3.1.6 • Published 8 months ago

wc-grid-table v3.1.6

Weekly downloads
44
License
ISC
Repository
github
Last release
8 months ago

wc-grid-table

codepen

Description

wc-grid-table (short: wgt) is a Free and Open-Source, CSS-Grid, Table WebComponent. The goal of this WebComponent is high customizability and a low barrier to entry. It uses no dependencys (lodash.debounce as optional plugin) and is only around 7kB (unzipped, minified) in size.

Installation

Install via npm:

npm install wc-grid-table

Use via CDN:

<scirpt src="https://unpkg.com/wc-grid-table@1.0.3/dist/standalone/bundle.min.js"></script>

Build from Source

First install all dev-dependecies:

npm install

wgt uses Browserify as bundler. In order to build the Component and all the examples you can run:

npm run build_all

Usage

Getting Started

Include it in your page:

<body>
  ...
  <script src="https://unpkg.com/wc-grid-table@1.0.3/dist/standalone/bundle.min.js"></script>
</body>

Afterwards the customElement should be registered. You can use the provided defineCustomElement() function, to register the component with the name wc-grid-table or call customElement yourself with a custom name:

WcGridTable.defineCustomElement();

// or

customElements.define('your-fancy-name', TableComponent);

The name has to (or should?!) include atleast one hyphen. After creating a wgt element the only thing needed is to add data:

// any sort of data
let data = [
  {
    firstname: "Hans",
    lastname: "Dieter",
    age: 28,
    hobby: "running"
  },{
    firstname: "Karl",
    lastname: "Heinrich",
    age: 52
  },{
    firstname: "Manfred",
    lastname: "Steibl",
    age: 60
  }
]

let table = document.createElement('wc-grid-table');
table.setData(data)

document.querySelector('body').append(table);

Customization

Methods

The following functions are exposed on the wgt element (documented in there respective docstring):

  • useDefaultOptions()
  • connectedCallback()
  • setDebounceFn(debounceFn, sortDebounceOptions, filterDebouncedOptions)
  • setData(data)
  • getDisplayedData()
  • getOriginalData()
  • redrawData()

Propertys

The following properties can be accessed / set directly on wgt element:

  • root_document - either document or the connected shadowRoot
  • conditionalColumnStyle - an object with keys condition, styles where condition is a function (data : Array<Object> , column : string) => Boolean and styles is an Array of strings with styles, that should apply when condition returns true for a column. Can be used to style a column in dependency of their data.
  • conditionalColumnOptions - an object with options concerning conditionalColumnStyle. Available Options:
    • active: Boolean
  • formatter - an Object with column names as keys, containing lists of formatter functions, that should be applied before displaing a table value. Formatter functions have this signature: (value, rowIndex, completeData) => any. Formatter get applied in the sequence they are in the list (leftmost function (2nd from left (3rd ...))).
  • formatterOptions - an object with options concerning formatter. Available Options:
    • active: Boolean
  • filter - an Object with column names as keys, containing strings which correspond to the filter input values in the ui. Those get validated by customFilterFunction / regexFilter.
  • filterOptions - an object with options concerning filter. Available Options:
    • active: Boolean
  • customFilterFunction - a function that can override default filter behaviour (regexFilter). Arguments are filter input values and value to test against as strings. The expected return is a filtered data Array.
  • sortedBy - an Array of Objects describing sorting. Keys are col - column name sorted - and dir - the sort direction (one of asc, desc). Sorting is kept after each sorting operation, so that primary, secondary, tertiary, ... sorting is possible.
  • sortOptions - an object with options concerning sorting. Available Options:
    • active: Boolean
  • customChooseSortsCompareFn - a function maps columns to sorting behavior. Expected return for given (table: TableComponent instance, data: Array, column: string) is a function to compare the values of this column.
  • customCompareNumbers | customCompareText - functions to replace default sort behavior corresponing to sorting numbers / text. Like default js CompareFn used in Array.prototype.sort

Attributes

The following Attributes can be set, to hide some parts of the ui:

  • noheader: hide header row
  • nofilter: hide filter row
  • nofooter: hide footer row

More to come.

License

Copyright 2019 Robert Seidler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

3.1.6

8 months ago

3.1.5

8 months ago

3.0.0

2 years ago

3.1.3

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.1.4

2 years ago

2.1.16

2 years ago

2.1.17

2 years ago

2.1.14

3 years ago

2.1.13

3 years ago

2.1.12

3 years ago

2.1.8

4 years ago

2.1.9

4 years ago

2.1.10

4 years ago

2.1.11

4 years ago

2.1.7

4 years ago

2.1.6

4 years ago

2.1.5

4 years ago

2.1.4

4 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.2.15

5 years ago

1.2.14

5 years ago

1.2.13

5 years ago

1.2.12

5 years ago

1.2.11

5 years ago

1.2.10

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago