protronic / prot-table

Customizable Vue Table Component
4 stars 1 forks source link

prot-table

Description

A customizable table component in vue. Intended to be used as a web-component or as a component in vue projects.

demo jsfiddle

Installation

Install from NPM

Run:

npm install prot-table

Build from Source

Install dependencies:

npm install

Build as Web-Component:

vue-cli-service build --mode production --dest dist/web-component --target wc --name prot-table && cp public/demo.html dist/index.html && cp public/data.json dist/data.json

Usage

Use as Web-Component

Include Vue and the Component:

import Vue from 'vue';
import 'prot-table/dist/web-component/prot-table';

Use as a Vue Component

Import it from prot-table and it gets registered as a Vue component for further use.

import ProtTable from 'prot-table'

Use the <prot-table></prot-table> tag with appropriate attributes:

<prot-table id="p1" data_url="data.json"></prot-table>

or create it from within javascript

let p = document.createElement('prot-table');
p.setAttribute('data_url', 'data.json');
document.body.append(p);

In order to change the appearance you can provide them via the table_options property.

  let p1 = document.createElement('prot-table')
  p1.setAttribute('data_url', "data.json");
  p1.table_options = {
    'height': '400px',
    'sortability': {
      'address': (a, b) => (Number(a.address.split(' ').pop()) - Number(b.address.split(' ').pop()))
    },
    'tableStyles': {},
    'headerStyles': {'font-weight': 'bold'},
    'bodyStyles': {},
    'rowStyles': [{
      check_row: (rowValues /*, rowIndex, vuexState, vuexGetters */ ) => ((rowValues['company'] && rowValues['company'] === 'INJOY') ? true : false),
      styles: {'background': 'lightgreen'}
    },{
      check_row: (rowValues /*, rowIndex, vuexState, vuexGetters */ ) => ((rowValues['index'] && rowValues['index'] > 40) ? true : false),
      styles: {'background': 'lightblue'}
    }],
    'colStyles': {'address': {'text-align': 'right'}},
    'formatter': {
      'index': (value /*, rowIndex, vuexState, vuexGetters */ ) => ((value < 10) ? `0${value}` : value),
      'isActive': (value /*, rowIndex, vuexState, vuexGetters */ ) => ((value) ? 'yes' : 'no'),
      'address': (value) => ((value) ? value.split(',').map( token => ((token.match(/\s[0-9]{3,4}/gm) ? `<span style="color: red;">${token}</span>` : token))).join(',') : '')
    },
    'cssVariables': {'--header-background': 'white'},
    'dontShowCols': ['_id'],
    'filters': {
      'connection_operation': 'and',
      'matchFilter': {},
      'inputRegExp': true,
      'showInputs': true,
    },
    'headerDef': {
      'index': {
        'displayName': 'Index',
        // 'fixWidth': '300px'
      },
      'isActive': {
        'displayName': 'Aktiv',
      },
      'first': {
        'displayName': 'Vorname',
      },
      'last': {
        'displayName': 'Nachname',
      },
      'company': {
        'displayName': 'Firma',
      },
      'address': {
        'displayName': 'Adresse',
      },
      'phone': {
        'displayName': 'Telefon',
      },
    }
  };
  document.body.append(p1);

Propertys

data_url: String

Url where the data can be fetched from. Data_url gets ignored when data property is set.

data: [Array, String]

A json string or an array of objects representing the table data grouped by rows.

table_options: [Object, String]

A json string or an object for all the table options.

License

Copyright 2019 Protronic GmbH

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.