-
Notifications
You must be signed in to change notification settings - Fork 26
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 #2804 from infor-design/2726-dropdown-editor-befor…
…ecelledit 2726 - IdsDataGrid dropdown editor async beforecelledit
- Loading branch information
Showing
6 changed files
with
252 additions
and
9 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
28 changes: 28 additions & 0 deletions
28
src/components/ids-data-grid/demos/beforecelledit-async.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 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title><%= htmlWebpackPlugin.options.title %></title> | ||
<%= htmlWebpackPlugin.options.font %> | ||
</head> | ||
<body> | ||
<ids-container role="main" padding="8" hidden> | ||
<ids-theme-switcher mode="light"></ids-theme-switcher> | ||
<ids-layout-grid auto-fit="true" padding="md"> | ||
<ids-text font-size="12" type="h1">Data Grid (Async Dropdown Options)</ids-text> | ||
</ids-layout-grid> | ||
<ids-layout-grid auto-fit="true" padding-x="md"> | ||
<ids-layout-grid-cell> | ||
<ids-data-grid | ||
id="data-grid-editable" | ||
suppress-row-click-selection="true" | ||
row-selection="multiple" | ||
label="Books" | ||
editable="true" | ||
edit-next-on-enter-press="true" | ||
add-new-at-end="true"> | ||
</ids-data-grid> | ||
</ids-layout-grid-cell> | ||
</ids-layout-grid> | ||
</ids-container> | ||
</body> | ||
</html> |
187 changes: 187 additions & 0 deletions
187
src/components/ids-data-grid/demos/beforecelledit-async.ts
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,187 @@ | ||
import '../ids-data-grid'; | ||
import type IdsDataGrid from '../ids-data-grid'; | ||
import type { IdsDataGridColumn } from '../ids-data-grid-column'; | ||
import booksJSON from '../../../assets/data/books.json'; | ||
|
||
// Example for populating the DataGrid | ||
const dataGrid = document.querySelector<IdsDataGrid>('#data-grid-editable')!; | ||
|
||
(async function init() { | ||
// Do an ajax request | ||
const url: any = booksJSON; | ||
const columns: IdsDataGridColumn[] = []; | ||
|
||
// Set up columns | ||
columns.push({ | ||
id: 'selectionCheckbox', | ||
name: 'selection', | ||
sortable: false, | ||
resizable: false, | ||
formatter: dataGrid.formatters.selectionCheckbox, | ||
align: 'center' | ||
}); | ||
columns.push({ | ||
id: 'description', | ||
name: 'Description', | ||
field: 'description', | ||
sortable: true, | ||
resizable: true, | ||
reorderable: true, | ||
formatter: dataGrid.formatters.text, | ||
editor: { | ||
type: 'input', | ||
editorSettings: { | ||
autoselect: true, | ||
dirtyTracker: true, | ||
validate: 'required', | ||
} | ||
}, | ||
readonly(row: number) { | ||
return row % 2 === 0; | ||
}, | ||
}); | ||
columns.push({ | ||
id: 'ledger', | ||
name: 'Ledger', | ||
field: 'ledger', | ||
resizable: true, | ||
reorderable: true, | ||
formatter: dataGrid.formatters.text, | ||
uppercase: true, | ||
editor: { | ||
type: 'input', | ||
editorSettings: { | ||
autoselect: true, | ||
dirtyTracker: true, | ||
maxlength: 2, | ||
uppercase: true | ||
} | ||
}, | ||
}); | ||
columns.push({ | ||
id: 'bookCurrency', | ||
name: 'Currency', | ||
field: 'bookCurrency', | ||
resizable: true, | ||
reorderable: true, | ||
uppercase: true, | ||
formatter: dataGrid.formatters.dropdown, | ||
editor: { | ||
type: 'dropdown', | ||
editorSettings: { | ||
dirtyTracker: true, | ||
validate: 'required' | ||
} | ||
} | ||
}); | ||
columns.push({ | ||
id: 'transactionCurrency', | ||
name: 'Transaction Currency', | ||
field: 'transactionCurrency', | ||
formatter: dataGrid.formatters.text | ||
}); | ||
columns.push({ | ||
id: 'integer', | ||
name: 'Price (Int)', | ||
field: 'price', | ||
formatter: dataGrid.formatters.integer, | ||
formatOptions: { locale: 'en-US' }, // Data Values are in en-US | ||
editor: { | ||
type: 'input', | ||
editorSettings: { | ||
autoselect: true, | ||
dirtyTracker: true, | ||
mask: 'number', | ||
maskOptions: { | ||
allowDecimal: false, | ||
integerLimit: 3 | ||
}, | ||
validate: 'required' | ||
} | ||
}, | ||
}); | ||
columns.push({ | ||
id: 'postHistory', | ||
name: 'Post History', | ||
field: 'postHistory', | ||
formatter: dataGrid.formatters.checkbox, | ||
align: 'center', | ||
editor: { | ||
type: 'checkbox', | ||
editorSettings: { | ||
dirtyTracker: true, | ||
} | ||
}, | ||
}); | ||
|
||
dataGrid.columns = columns; | ||
dataGrid.idColumn = 'book'; | ||
|
||
const setData = async () => { | ||
const res = await fetch(url); | ||
const data = await res.json(); | ||
dataGrid.data = data; | ||
}; | ||
|
||
await setData(); | ||
|
||
type Currency = { | ||
id: string, | ||
label: string, | ||
value: string | ||
}; | ||
|
||
// simulate the delay of the options coming from the server | ||
const fetchCurrencies = new Promise<Array<Currency>>((resolve) => { | ||
setTimeout(() => { | ||
resolve([ | ||
{ | ||
id: 'usd', | ||
label: 'USD', | ||
value: 'usd' | ||
}, | ||
{ | ||
id: 'eur', | ||
label: 'EUR', | ||
value: 'eur' | ||
}, | ||
{ | ||
id: 'yen', | ||
label: 'YEN', | ||
value: 'yen' | ||
}, | ||
{ | ||
id: 'cad', | ||
label: 'CAD', | ||
value: 'cad' | ||
}, | ||
{ | ||
id: 'gbp', | ||
label: 'GBP', | ||
value: 'gbp' | ||
}, | ||
{ | ||
id: 'ars', | ||
label: 'ARS', | ||
value: 'ars' | ||
} | ||
]); | ||
}, 200); | ||
}); | ||
|
||
// Event Handlers | ||
dataGrid.addEventListener('beforecelledit', ((evt: CustomEvent) => { | ||
// Can be vetoed (<CustomEvent>e).detail.response(false); | ||
console.info(`Edit Started`, evt.detail); | ||
const colId = evt.detail.column.id; | ||
const editor = evt.detail.column.editor; | ||
|
||
if (editor && colId === 'bookCurrency' && !editor.editorSettings.options?.length) { | ||
evt.detail.response(async () => { | ||
const currencies = await fetchCurrencies; | ||
editor.editorSettings.options = currencies; | ||
return true; | ||
}); | ||
} | ||
}) as EventListener); | ||
}()); |
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