Skip to content

Commit cae01e0

Browse files
committed
example with multiple tables
1 parent 262abe4 commit cae01e0

File tree

8 files changed

+243
-235
lines changed

8 files changed

+243
-235
lines changed

dist/array-utils.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11

2-
function refresh(table) {
3-
table.setAttribute('table_data', JSON.stringify({}));
4-
table.setAttribute('table_data', JSON.stringify(myData));
5-
}
6-
72
function arrayRemove(arr, value) {
83
return arr.filter(function (ele, i) {
94
return i !== value;

dist/build/crud-table.js

Lines changed: 103 additions & 104 deletions
Large diffs are not rendered by default.

dist/build/crud-table.mjs

Lines changed: 103 additions & 104 deletions
Large diffs are not rendered by default.

dist/crud-table-2-config-html.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let table_config2 = {
77
{name: 'name', show: true, edit: true, width: '150px', tooltip: true},
88
{name: 'job', show: true, edit: true, width: '150px', description: 'The job'},
99
{name: 'private', show: true, edit: true, width: '200px', description: 'your things', tooltip: true},
10-
{name: 'html', show: true, edit: true, width: '500px', type: 'html', description: 'You can use HTML', tooltip: true}
10+
{name: 'html', show: true, edit: true, width: '150px', type: 'html', description: 'You can use HTML', tooltip: true}
1111
],
1212
row_settings: {height: '1.3em'}
1313
}
@@ -17,12 +17,12 @@ let genericCrudTable2 = document.getElementById('crud-table-2');
1717
const sortStore2 = [];
1818

1919
genericCrudTable2.setAttribute('table_config', JSON.stringify(table_config2));
20-
genericCrudTable2.setAttribute('table_data', JSON.stringify(myData));
20+
genericCrudTable2.setAttribute('table_data', JSON.stringify(myData2));
2121

2222
genericCrudTable2.addEventListener('create', () => {
2323
console.log('create');
24-
myData.unshift({id: Date.now().toString(), name: 'A_NEW', job: 'none', private: 'set hard', html: 'a <b>b</b> <i>c</i>'});
25-
refresh();
24+
myData2.unshift({id: Date.now().toString(), name: 'A_NEW', job: 'none', private: 'set hard', html: 'a <b>b</b> <i>c</i>'});
25+
genericCrudTable2.setAttribute('table_data', JSON.stringify(myData2));
2626
});
2727

2828
genericCrudTable2.addEventListener('details', (e) => {
@@ -33,25 +33,25 @@ genericCrudTable2.addEventListener('details', (e) => {
3333
genericCrudTable2.addEventListener('update', (e) => {
3434
console.log('update');
3535
console.log(e.detail.body);
36-
for(let i = 0; i < myData.length; i++) {
37-
if (JSON.stringify(myData[i]) === JSON.stringify(table_data[e.detail.id])) {
38-
myData[i] = e.detail.body;
36+
for(let i = 0; i < myData2.length; i++) {
37+
if (JSON.stringify(myData2[i]) === JSON.stringify(table_data[e.detail.id])) {
38+
myData2[i] = e.detail.body;
3939
break;
4040
}
4141
}
42-
refresh(genericCrudTable2);
42+
genericCrudTable2.setAttribute('table_data', JSON.stringify(myData2));
4343
});
4444

4545
genericCrudTable2.addEventListener('delete', (e) => {
4646
console.log('delete: ' + JSON.stringify(e.detail.body));
4747
console.log('offset in view:' + e.detail.id);
48-
for(let i = 0; i < myData.length; i++) {
49-
if (JSON.stringify(myData[i]) === JSON.stringify(myData[e.detail.id])) {
50-
myData = arrayRemove(myData, i)
48+
for(let i = 0; i < myData2.length; i++) {
49+
if (JSON.stringify(myData2[i]) === JSON.stringify(myData2[e.detail.id])) {
50+
myData2 = arrayRemove(myData2, i)
5151
break;
5252
}
5353
}
54-
refresh(genericCrudTable2);
54+
genericCrudTable2.setAttribute('table_data', JSON.stringify(myData2));
5555
});
5656

5757
genericCrudTable2.addEventListener('sort', (e) => {
@@ -76,6 +76,6 @@ genericCrudTable2.addEventListener('sort', (e) => {
7676
return 0;
7777
};
7878

79-
myData = myData.sort(tableSort);
80-
refresh(genericCrudTable2);
79+
myData2 = myData2.sort(tableSort);
80+
genericCrudTable2.setAttribute('table_data', JSON.stringify(myData2));
8181
});

dist/index.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ <h1>&lt;crud-table&gt;&lt;/crud-table&gt;</h1>
1414
<p>Agnostic web-component for object-arrays with CRUD functionality.</p>
1515
<span style="background-color: #dddddd; padding: 0.4em; display:inline-block">&gt; npm install svelte-generic-crud-table --save-dev</span>
1616
<p></p>
17+
<hr>
18+
<p>Table 1:</p>
19+
<crud-table id="crud-table-2"></crud-table>
20+
<br>
21+
<hr>
22+
<p>Table 2 configuration example:</p>
1723
<blockquote><pre><code>
1824
const table_config = {
1925
name: 'Awesome',
@@ -28,7 +34,6 @@ <h1>&lt;crud-table&gt;&lt;/crud-table&gt;</h1>
2834
details_text: 'detail' // replace the standard icon with an text-link
2935
}
3036
</code></pre></blockquote>
31-
<hr>
3237
<crud-table id="crud-table-1"></crud-table>
3338
<hr>
3439
</span style="text-align: right"><a href="https://ivolution.one">ivolution.one product - MIT License</a>
@@ -44,7 +49,9 @@ <h1>&lt;crud-table&gt;&lt;/crud-table&gt;</h1>
4449
<img src="https://github.com/ivosdc/svelte-generic-crud-table/raw/master/assets/donate.gif" title="donate">
4550
</a></p>
4651
</body>
47-
<script src='test-data.js'></script>
4852
<script src='array-utils.js'></script>
53+
<script src='test-data.js'></script>
4954
<script src='crud-table-1-config-html.js'></script>
55+
<script src='test-data2.js'></script>
56+
<script src='crud-table-2-config-html.js'></script>
5057
</html>

dist/test-data2.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-generic-crud-table",
3-
"version": "1.5.82",
3+
"version": "1.5.83",
44
"description": "<crud-table> renders object-arrays with options-panel and inline edit per row. Dispatches events for ongoing data handling. As self-containing webcomponent or for Svelte in 60KB",
55
"main": "dist/build/crud-table.js",
66
"module": "dist/build/crud-table.mjs",

src/SvelteGenericCrudTable.svelte

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
const CREATE = 'CREATE';
99
const DETAILS = 'DETAILS';
1010
11-
const SHOW = true;
12-
const HIDE = false;
13-
1411
const table_config_default = {
1512
name: 'crud-table',
1613
options: ['CREATE', 'EDIT', 'DELETE', 'DETAILS'],
@@ -133,8 +130,8 @@
133130
const columnsWidth = [];
134131
const columnsResize = [];
135132
136-
function tableNameToId(name) {
137-
return name.replace(':', '').replace(' ', '');
133+
function tableNameToId(tableName) {
134+
return tableName.replace(':', '').replace(' ', '');
138135
}
139136
140137
function handleResize(event) {

0 commit comments

Comments
 (0)