Skip to content

Commit 370337c

Browse files
committed
Editable for check.
1 parent d003c0a commit 370337c

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

src/pg/table/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ this.$table.columns = [{
3737
key: 'check',
3838
hideLabel: true,
3939
type: TableHeaderCheck,
40+
editable: true
4041
}, {
4142
label: 'Name',
4243
key: 'name'
@@ -50,6 +51,8 @@ this.$table.columns = [{
5051
}];
5152
```
5253

54+
Adding `editable: true` to any data types will enable editing and trigger the `action` event (see Events below).
55+
5356
## Data
5457

5558
The `createTableItem` unrolls the `{ key: value }` shorthand to `items: [{ key, value}]` object to support the mutable data.
@@ -84,8 +87,13 @@ All events dispatched will be the same `action` name. This allows the insert of
8487
```typescript
8588
this.$table.addEventListener('action', (e: any) => {
8689
const { getColumn, value, key } = e.detail;
87-
// do custom logic based on key
88-
getColumn(key).value = value;
90+
switch(key) {
91+
case 'selected':
92+
getColumn(key).value = value;
93+
break;
94+
default:
95+
throw `unhandled action event for key ${key}`;
96+
}
8997
});
9098
```
9199

src/pg/table/__examples__/basic/basic.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default class XPgTableBasic extends HTMLElement {
2727
label: 'Select',
2828
key: 'selected',
2929
hideLabel: true,
30+
editable: true,
3031
}, {
3132
label: 'Name',
3233
key: 'name'

src/pg/table/table.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ export default class PgTable extends HTMLElement {
5656
container: this.$rows,
5757
items: this.data,
5858
type: () => PgTableRow,
59-
create: ($item, item) => {
59+
create: ($item: PgTableRow, item) => {
60+
if (this.columns.length === 0) {
61+
throw 'columns must be set before data';
62+
}
63+
$item.columns = this.columns;
6064
$item.addEventListener('action', (e: any) => {
6165
e.stopPropagation();
6266
this.dispatchEvent(new CustomEvent('action', {

src/pg/tableRow/tableRow.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ const types = new Map<string, any>([
2020
})
2121
export default class PgTableRow extends HTMLElement {
2222
@Prop() index: number;
23-
@Prop() items: any = [];
23+
@Prop() items: any[] = [];
2424
@Prop() key: string = '';
25+
@Prop() columns: any[] = [];
2526

2627
@Part() $cells: HTMLDivElement;
2728

@@ -34,7 +35,12 @@ export default class PgTableRow extends HTMLElement {
3435
? item.type
3536
: types.get(typeof item.value);
3637
},
37-
create: ($item, item) => {
38+
create: ($item: any, item) => {
39+
console.log(this.columns.find(i => i.key === item.key));
40+
const { editable } = this.columns.find(i => i.key === item.key) ?? {};
41+
if (editable) {
42+
$item.editable = editable;
43+
}
3844
$item.addEventListener('action', (e: any) => {
3945
e.stopPropagation();
4046
this.dispatchEvent(new CustomEvent('action', {

0 commit comments

Comments
 (0)