forked from jackdough/lwc-listview
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from shliachtx/picklist
Picklist
- Loading branch information
Showing
18 changed files
with
267 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import LightningDatatable from 'lightning/datatable'; | ||
import picklistField from './picklistField.html'; | ||
|
||
export default class DatatableBase extends LightningDatatable { | ||
static customTypes = { | ||
picklist: { | ||
template: picklistField, | ||
typeAttributes: ['options','editable'] | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/lwc/datatableBase/datatableBase.js-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>47.0</apiVersion> | ||
<isExposed>false</isExposed> | ||
</LightningComponentBundle> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<template> | ||
<c-datatable-picklist-field | ||
row-key-value={rowKeyValue} | ||
col-key-value={colKeyValue} | ||
value={value} | ||
editable={typeAttributes.editable} | ||
options={typeAttributes.options} | ||
></c-datatable-picklist-field> | ||
</template> |
39 changes: 39 additions & 0 deletions
39
force-app/main/default/lwc/datatablePicklistField/datatablePicklistField.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
:host>div { | ||
display: block; | ||
padding: var(--lwc-spacingXxSmall); | ||
margin: 1px; | ||
} | ||
|
||
.editable:hover { | ||
background-color: white; | ||
} | ||
|
||
.edit-button { | ||
visibility: hidden; | ||
} | ||
|
||
:host:hover .edit-button { | ||
visibility: visible; | ||
opacity: .5; | ||
} | ||
|
||
:host:focus .editable .edit-button { | ||
visibility: visible; | ||
opacity: 1; | ||
} | ||
|
||
.editor { | ||
position: absolute !important; | ||
min-width: 100%; | ||
z-index: 1; | ||
top: -1px; | ||
left: -1px; | ||
display:block; | ||
background-color:white; | ||
border: 1px solid lightgray; | ||
padding: var(--lwc-spacingXxSmall); | ||
} | ||
|
||
lightning-combobox { | ||
min-width: 100%; | ||
} |
28 changes: 28 additions & 0 deletions
28
force-app/main/default/lwc/datatablePicklistField/datatablePicklistField.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<template> | ||
<div class={editClass}> | ||
<div class="slds-grid slds-grid_align-spread"> | ||
<span>{displayValue}</span> | ||
<template if:true={editable}> | ||
<lightning-button-icon | ||
class="slds-m-left_x-small edit-button" | ||
icon-class="slds-icon-text-default" | ||
variant="bare" | ||
icon-name="utility:edit" | ||
onclick={handleEdit} | ||
> | ||
</lightning-button-icon | ||
> | ||
</template> | ||
</div> | ||
</div> | ||
<div class="editor" if:true={editing}> | ||
<lightning-combobox | ||
name="picklist" | ||
variant="label-hidden" | ||
value={value} | ||
options={options} | ||
onchange={handleChange} | ||
onblur={handleFocusout}> | ||
</lightning-combobox> | ||
</div> | ||
</template> |
77 changes: 77 additions & 0 deletions
77
force-app/main/default/lwc/datatablePicklistField/datatablePicklistField.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { LightningElement, api, track, wire } from 'lwc'; | ||
// import displayTemplate from './display.html'; | ||
// import editTemplate from './edit.html' | ||
|
||
export default class DatatablePicklistField extends LightningElement { | ||
@api rowKeyValue; | ||
@api colKeyValue; | ||
@api | ||
get value() { | ||
return this._value; | ||
} | ||
set value(val) { | ||
this._value = val; | ||
this._editedValue = val; | ||
} | ||
@api | ||
get options() { | ||
return this._options; | ||
} | ||
set options(value) { | ||
this._options = value; | ||
this.valueToLabelMap = value.reduce((acc,opt) => { | ||
acc[opt.value] = opt.label; | ||
return acc; | ||
}, {}); | ||
} | ||
@api editable; | ||
|
||
@track editing; | ||
@track _options; | ||
_editedValue; | ||
valueToLabelMap={}; | ||
editRendered; | ||
|
||
renderedCallback() { | ||
const combobox = this.template.querySelector('lightning-combobox'); | ||
if (!combobox) { | ||
this.editRendered = false; | ||
} else if (!this.editRendered ) { | ||
combobox.focus(); | ||
this.editRendered = true; | ||
} | ||
} | ||
handleFocusout() { | ||
if (this._editedValue !== this._value) { | ||
this.dispatchEvent(new CustomEvent('inlineedit', { | ||
detail: { | ||
value: this._editedValue, | ||
rowKeyValue: this.rowKeyValue, | ||
colKeyValue: this.colKeyValue | ||
}, | ||
bubbles: true, | ||
composed: true | ||
})); | ||
} | ||
this.editing=false; | ||
} | ||
|
||
handleEdit() { | ||
this.editing=true; | ||
|
||
} | ||
|
||
handleChange(event) { | ||
this._editedValue = event.detail.value; | ||
// this.template.focus(); | ||
} | ||
|
||
get editClass() { | ||
return this.editable ? 'editable ' : ''; | ||
} | ||
|
||
get displayValue() { | ||
return this.valueToLabelMap[this.value] || this.value; | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/lwc/datatablePicklistField/datatablePicklistField.js-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>47.0</apiVersion> | ||
<isExposed>false</isExposed> | ||
</LightningComponentBundle> |
18 changes: 18 additions & 0 deletions
18
force-app/main/default/lwc/datatablePicklistField/display.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<template> | ||
<div class={editClass}> | ||
<div class="slds-grid slds-grid_align-spread"> | ||
{value} | ||
<template if:true={editable}> | ||
<lightning-button-icon | ||
class="slds-m-left_x-small edit-button" | ||
icon-class="slds-icon-text-default" | ||
variant="bare" | ||
icon-name="utility:edit" | ||
onclick={handleEdit} | ||
> | ||
</lightning-button-icon | ||
> | ||
</template> | ||
</div> | ||
</div> | ||
</template> |
16 changes: 16 additions & 0 deletions
16
force-app/main/default/lwc/datatablePicklistField/edit.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
:host { | ||
position: absolute !important; | ||
min-width: 100%; | ||
z-index: 1; | ||
top: 0; | ||
display:block; | ||
background-color:white; | ||
border: 1px solid lightgray; | ||
padding: var(--lwc-spacingXxSmall); | ||
} | ||
|
||
.label-hideen | ||
|
||
lightning-combobox { | ||
min-width: 100%; | ||
} |
10 changes: 10 additions & 0 deletions
10
force-app/main/default/lwc/datatablePicklistField/edit.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<template> | ||
<lightning-combobox | ||
name="picklist" | ||
variant="label-hidden" | ||
value={value} | ||
options={myoptions} | ||
onchange={handleChange} | ||
onblur={handleFocusout}> | ||
</lightning-combobox> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters