All Projects → ivosdc → svelte-generic-crud-table

ivosdc / svelte-generic-crud-table

Licence: MIT License
Agnostic web-component for object-arrays with CRUD functionality.

Programming Languages

javascript
184084 projects - #8 most used programming language
Svelte
593 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to svelte-generic-crud-table

Svelte Simple Datatables
A Datatable component for Svelte
Stars: ✭ 56 (+47.37%)
Mutual labels:  table, svelte
svelte-trivia
A Quiz app completely made using Svelte
Stars: ✭ 25 (-34.21%)
Mutual labels:  svelte
svelte-fullcalendar
A Svelte component wrapper around FullCalendar
Stars: ✭ 123 (+223.68%)
Mutual labels:  svelte
svelteit
Svelteit is a minimalistic UI/UX component library for Svelte and Sapper projects
Stars: ✭ 64 (+68.42%)
Mutual labels:  svelte
sveld
Generate TypeScript definitions for your Svelte components
Stars: ✭ 281 (+639.47%)
Mutual labels:  svelte
survey-analytics
SurveyJS Analytics Pack
Stars: ✭ 56 (+47.37%)
Mutual labels:  table
table-layout
Styleable plain-text table generator. Useful for formatting console output.
Stars: ✭ 18 (-52.63%)
Mutual labels:  table
svelte-fast-dimension
Fast dimension bindings using ResizeObservers
Stars: ✭ 23 (-39.47%)
Mutual labels:  svelte
svelte-meteor-data
Reactively track Meteor data inside Svelte components
Stars: ✭ 14 (-63.16%)
Mutual labels:  svelte
safenetwork-gitportal
p2p git portal - a decentralised alternative to github
Stars: ✭ 12 (-68.42%)
Mutual labels:  svelte
todomvc-svelte
TodoMVC built with Svelte and Store
Stars: ✭ 34 (-10.53%)
Mutual labels:  svelte
svelte-avatar
An avatar component for Svelte
Stars: ✭ 12 (-68.42%)
Mutual labels:  svelte
modern-fluid-typography-editor
Modern fluid typography editor
Stars: ✭ 222 (+484.21%)
Mutual labels:  svelte
svelte-starter-kit
Svelte with brilliant bells and useful whistles
Stars: ✭ 384 (+910.53%)
Mutual labels:  svelte
Feliz.MaterialUI.MaterialTable
Fable bindings written in the Feliz-style for material-table.
Stars: ✭ 17 (-55.26%)
Mutual labels:  table
react-keyview
React components to display the list, table, and grid, without scrolling, use the keyboard keys to navigate through the data
Stars: ✭ 16 (-57.89%)
Mutual labels:  table
focus-svelte
focus lock for svelte
Stars: ✭ 18 (-52.63%)
Mutual labels:  svelte
svelte-pdf
svelte-pdf provides a component for rendering PDF documents using PDF.js
Stars: ✭ 102 (+168.42%)
Mutual labels:  svelte
svelte-router
Router component for Svelte
Stars: ✭ 63 (+65.79%)
Mutual labels:  svelte
sveltober
Cybernetically enhanced October applications
Stars: ✭ 19 (-50%)
Mutual labels:  svelte

svelte-generic-crud-table

  • Web-component: <crud-table></crud-table>
  • or Svelte-component: import SvelteGenericCrudTable from 'svelte-generic-crud-table'

A self-containing sortable table component with inline edit option. See <table-pager> with integrated paginator for pagination. table-pager

Allows CRUD-operations for Object-Arrays.

Try out live example:

Published on webcomponents.org

Install

npm install svelte-generic-crud-table --save-dev

State (master):

Build Status Coverage Status

Usage

Use the svelte-generic-crud-table in your component to show and, if you like, edit,update and delete it's content. Just include the table as seen in the example below.

column settings

All fields are optional.

Settings regarding a column behaviour can be specified in the table_config. Only wanted keys of your source array have to be mapped by columns_settings name. All other attributes are optional.

    const table_config = {
        name: 'Awesome',
        options: ['CREATE', 'EDIT', 'DELETE', 'DETAILS'],
        columns_setting: [
            {name: 'id', show: false, edit: true, width: '0px'},
            {name: 'job', show: true, edit: true, width: '150px', description: 'The job'},
            {name: 'name', show: true, edit: true, width: '150px', tooltip: true},
            {name: 'private', show: true, edit: false, width: '200px', description: 'your things', tooltip: true},
            {name: 'html', show: true, edit: true, width: '500px', type: 'html', description: 'You can use HTML', tooltip: true}
        ],
        details_text: 'detail'   // replace the standard icon with an text-link
    }
  • name: the key from your data-array. This is used as column name.
  • show: true/false; Should this column displayed? (optional, default: false)
  • edit: true/false; Set this field editable or not. (optional, default: false)
  • width: px/em; set the field width. (optional, default: 100px)
  • description: A tooltip for the columns name. E.g. to see the full name or other description. (optional, default: unset)
  • tooltip: true/false; When the text does not fit into the field you can show the full text as tooltip. (optional, default: false)
  • type: There are two types: (optional, default: text)
    • text: Default.
    • html: The value/text will be interpreted as HTML.

See example:

<crud-table></crud-table>

<custom-element-demo>
<template>
<head>
    <meta charset='utf-8'>
    <meta name='viewport' content='width=device-width,initial-scale=1'>
    <title>Generic Crud Table</title>
    <link rel='icon' type='image/png' href='favicon.png'>
    <script defer src='https://ivosdc.github.io/svelte-generic-crud-table/build/crud-table.js'></script>
</head>

<body>
<hr>
<crud-table></crud-table>
<hr>
</body>
<script src='https://ivosdc.github.io/svelte-generic-crud-table/test-data.js'></script>
<script src='https://ivosdc.github.io/svelte-generic-crud-table/crud-table-config-html.js'></script>
</template>
</custom-element-demo>
<crud-table></crud-table>

Svelte-Component - implementation example:

<script>
    import SvelteGenericCrudTable from "svelte-generic-crud-table";
    import {onMount} from 'svelte';
    import {goto} from "@sapper/app";

    const sortStore = [];

    let myData = [];

    onMount(reload);

    function reload() {
        get().then( (result) => {
                myData = result;
        });
    }

    function handleCreate(event) {
        post({name: "new entry"}).then(() => {
                    reload();
                });
    }


    function handleDelete(event) {
        delete(event.detail.body.id).then(() => {
                    reload();
                });
    }

    function handleUpdate(event) {
        update(event.detail.body.id, event.detail.body)
                .then(() => {
                    reload();
                });
    }

    function handleDetail(event) {
        goto('/project/' + event.detail.body.id);
    }

    function handleSort(event) {
        const column = event.detail.column;
        if (sortStore[column] === undefined || sortStore[column] === 'DESC') {
            sortStore[column] = 'ASC';
        } else {
            sortStore[column] = 'DESC';
        }

        const tableSort = (a, b) => {
            var keyA = a[column];
            var keyB = b[column];
            if (sortStore[column] === 'ASC') {
                if (keyA < keyB) return -1;
                if (keyA > keyB) return 1;
            } else {
                if (keyA < keyB) return 1;
                if (keyA > keyB) return -1;
            }
            return 0;
        };

        myData = myData.sort(tableSort);
    }

    const table_config = {
        name: 'Awesome',
        options: ['CREATE', 'EDIT', 'DELETE', 'DETAILS'],
        columns_setting: [
            {name: 'id', show: false, edit: true, width: '200px'},
            {name: 'job', show: true, edit: true, width: '100px', description: 'Your Job'},
            {name: 'name', show: true, edit: true, width: '200px', tooltip: true},
            {name: 'private', show: true, edit: false, width: '200px', description: 'Your things'},
            {name: 'html', show: true, edit: true, size: '200px', type: 'html', tooltip: true}
        ],
        details_text: 'detail'   // replace the standard icon with an text-link
    }

</script>

<main>
    <SvelteGenericCrudTable on:delete={handleDelete}
                            on:update={handleUpdate}
                            on:create={handleCreate}
                            on:details={handleDetail}
                            on:sort={handleSort}
                            table_config={table_config}
                            table_data={myData}/>
</main>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].