33- or Svelte-component: ` import SvelteGenericCrudTable from 'svelte-generic-crud-table' `
44
55A self-containing sortable table component with inline edit option.
6- See ` <table-pager> ` with integrated paginator for pagination.
7- [ table-pager] ( https://www.npmjs.com/package/svelte-generic-table-pager/ " CrudTable with paginator Example ")
86
97Allows CRUD-operations for Object-Arrays.
108
@@ -20,10 +18,6 @@ npm install svelte-generic-crud-table --save-dev
2018```
2119
2220
23- ### State (master):
24- [ ![ Build Status] ( https://travis-ci.com/ivosdc/svelte-generic-crud-table.svg?branch=master )] ( https://travis-ci.com/ivosdc/svelte-generic-crud-table )
25- [ ![ Coverage Status] ( https://coveralls.io/repos/github/ivosdc/svelte-generic-crud-table/badge.svg?branch=master )] ( https://coveralls.io/github/ivosdc/svelte-generic-crud-table?branch=master )
26-
2721# Usage
2822Use the svelte-generic-crud-table in your component to show and, if you like, edit,update and delete it's content.
2923Just include the table as seen in the example below.
@@ -39,15 +33,16 @@ Only wanted keys of your source array have to be mapped by columns_settings *nam
3933 options: ['CREATE', 'EDIT', 'DELETE', 'DETAILS'],
4034 columns_setting: [
4135 {name: 'id', show: false, edit: true, width: '0px'},
42- {name: 'job', show: true, edit: true, width: '150px', description: 'The job'},
43- {name: 'name', show: true, edit: true, width: '150px', tooltip: true},
36+ {name: 'job', displayName: 'Top-Jobs', show: true, edit: true, width: '150px', description: 'The job'},
37+ {name: 'name', displayName: 'Account-ID', show: true, edit: true, width: '150px', tooltip: true},
4438 {name: 'private', show: true, edit: false, width: '200px', description: 'your things', tooltip: true},
4539 {name: 'html', show: true, edit: true, width: '500px', type: 'html', description: 'You can use HTML', tooltip: true}
4640 ],
4741 details_text: 'detail' // replace the standard icon with an text-link
4842 }
4943```
5044- <b >* name* </b >: the key from your data-array. This is used as column name.
45+ - * displayName* : An alternative column header if * name* is not matching the needs.
5146- * show* : true/false; Should this column displayed? (optional, default: false)
5247- * edit* : true/false; Set this field editable or not. (optional, default: false)
5348- * width* : px/em; set the field width. (optional, default: 100px)
@@ -93,8 +88,6 @@ Only wanted keys of your source array have to be mapped by columns_settings *nam
9388 import {onMount } from ' svelte' ;
9489 import {goto } from " @sapper/app" ;
9590
96- const sortStore = [];
97-
9891 let myData = [];
9992
10093 onMount (reload);
@@ -129,30 +122,7 @@ Only wanted keys of your source array have to be mapped by columns_settings *nam
129122 goto (' /project/' + event .detail .body .id );
130123 }
131124
132- function handleSort (event ) {
133- const column = event .detail .column ;
134- if (sortStore[column] === undefined || sortStore[column] === ' DESC' ) {
135- sortStore[column] = ' ASC' ;
136- } else {
137- sortStore[column] = ' DESC' ;
138- }
139-
140- const tableSort = (a , b ) => {
141- var keyA = a[column];
142- var keyB = b[column];
143- if (sortStore[column] === ' ASC' ) {
144- if (keyA < keyB) return - 1 ;
145- if (keyA > keyB) return 1 ;
146- } else {
147- if (keyA < keyB) return 1 ;
148- if (keyA > keyB) return - 1 ;
149- }
150- return 0 ;
151- };
152-
153- myData = myData .sort (tableSort);
154- }
155-
125+
156126 const table_config = {
157127 name: ' Awesome' ,
158128 options: [' CREATE' , ' EDIT' , ' DELETE' , ' DETAILS' ],
@@ -173,7 +143,6 @@ Only wanted keys of your source array have to be mapped by columns_settings *nam
173143 on:update ={handleUpdate}
174144 on:create ={handleCreate}
175145 on:details ={handleDetail}
176- on:sort ={handleSort}
177146 table_config ={table_config}
178147 table_data ={myData}/ >
179148</main >
0 commit comments