Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix some problems found with AutoComplete #74

Merged
merged 2 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/app.06333a13bf16d79e2b6d.bundle.map

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/app.4c7e5103b75b098aec5d.bundle.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/app.523343e25b1b252315f4.bundle.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html><head><meta charset="utf-8"><title>Slickgrid-Universal</title><meta name="viewport" content="width=device-width,initial-scale=1"><base href=""><link rel="icon" href="favicon.ico"><link href="app.523343e25b1b252315f4.bundle.css" rel="stylesheet"></head><body class="has-navbar-fixed-top"><script async defer="defer" src="//buttons.github.io/buttons.js"></script><div app="main"><div style="margin: 50px; font-weight: bold;">LOADING...</div></div><script src="app.06333a13bf16d79e2b6d.bundle.js"></script></body></html>
<!doctype html><html><head><meta charset="utf-8"><title>Slickgrid-Universal</title><meta name="viewport" content="width=device-width,initial-scale=1"><base href=""><link rel="icon" href="favicon.ico"><link href="app.523343e25b1b252315f4.bundle.css" rel="stylesheet"></head><body class="has-navbar-fixed-top"><script async defer="defer" src="//buttons.github.io/buttons.js"></script><div app="main"><div style="margin: 50px; font-weight: bold;">LOADING...</div></div><script src="app.4c7e5103b75b098aec5d.bundle.js"></script></body></html>
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ <h4 class="subtitle is-italic has-text-primary-dark">
<div class="modal-grid"></div>
</section>
<footer class="modal-card-foot" style="justify-content: flex-end;">
<button class="button close is-small">Cancel</button>
<button class="button is-success" onclick.delegate="saveMassUpdate()">Save changes</button>
<button class="button close">Cancel</button>
<button class="button is-info" onclick.delegate="saveMassUpdate('mass')">Mass Update</button>
<button class="button is-success" onclick.delegate="saveMassUpdate('selection')">Update Selected Rows</button>
</footer>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class Example11Modal {
}
}

saveMassUpdate() {
saveMassUpdate(updateType: 'selection' | 'mass') {
this.handleOnModalClose();
const editedItem = this.sgb.dataView.getItemByIdx(0);

Expand All @@ -122,7 +122,7 @@ export class Example11Modal {
}

// finally execute the remote callback
this.remoteCallbackFn(editedItem, this.selectedIds);
this.remoteCallbackFn({ item: editedItem, selectedIds: this.selectedIds, updateType });
}
}

Expand Down
55 changes: 26 additions & 29 deletions examples/webpack-demo-vanilla-bundle/src/examples/example11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class Example11 {
formatter: Formatters.complexObject,
type: FieldType.object,
sortComparer: SortComparers.objectString,
params: { massUpdate: true },
editor: {
model: Editors.autoComplete,
alwaysSaveOnEnterKey: true,
Expand Down Expand Up @@ -182,6 +183,7 @@ export class Example11 {
filterable: true,
sortable: true,
minWidth: 100,
params: { massUpdate: true },
editor: {
model: Editors.autoComplete,
alwaysSaveOnEnterKey: true,
Expand Down Expand Up @@ -373,21 +375,14 @@ export class Example11 {
}
break;
case 'modal':
const selectedRowIndexes = this.sgb.slickGrid.getSelectedRows() || [];
let confirmed = true;

if (selectedRowIndexes.length === 0) {
confirmed = await confirm(`Since no rows were selected, we'll assume you want to do a mass update on every row. \n\nOK to continue \nCancel to return to the grid`);
}

if (confirmed) {
const modalContainerElm = document.querySelector<HTMLDivElement>('.modal-container');
const columnDefinitionsClone = deepCopy(this.columnDefinitions);
const massUpdateColumnDefinitions = columnDefinitionsClone?.filter((col: Column) => col.params?.massUpdate === true) || [];
const selectedItems = this.sgb.gridService.getSelectedRowsDataItem();
const selectedIds = selectedItems.map(selectedItem => selectedItem.id);
loadComponent(modalContainerElm, './example11-modal', { columnDefinitions: massUpdateColumnDefinitions, selectedIds, remoteCallback: this.remoteCallbackFn.bind(this) });
}
this.sgb.slickGrid.getSelectedRows() || [];
const modalContainerElm = document.querySelector<HTMLDivElement>('.modal-container');
const columnDefinitionsClone = deepCopy(this.columnDefinitions);
const massUpdateColumnDefinitions = columnDefinitionsClone?.filter((col: Column) => col.params?.massUpdate === true) || [];
const selectedItems = this.sgb.gridService.getSelectedRowsDataItem();
const selectedIds = selectedItems.map(selectedItem => selectedItem.id);
loadComponent(modalContainerElm, './example11-modal', { columnDefinitions: massUpdateColumnDefinitions, selectedIds, remoteCallback: this.remoteCallbackFn.bind(this) });
break;
}
}

Expand Down Expand Up @@ -417,37 +412,39 @@ export class Example11 {
}
}

remoteCallbackFn(massUpdateItem: any, selectedIds: string[]) {
remoteCallbackFn(args: { item: any, selectedIds: string[], updateType: 'selection' | 'mass' }) {
const fields = [];
for (const key in massUpdateItem) {
if (massUpdateItem.hasOwnProperty(key)) {
fields.push({ fieldName: key, value: massUpdateItem[key] });
for (const key in args.item) {
if (args.item.hasOwnProperty(key)) {
fields.push({ fieldName: key, value: args.item[key] });
}
}
console.log('Remote Callback', massUpdateItem, fields);
console.log('Remote Callback', args, fields);

if (Array.isArray(selectedIds) && selectedIds.length > 0) {
if (args.updateType === 'selection' && Array.isArray(args.selectedIds) && args.selectedIds.length > 0) {
// update only the selected rows
const updatedItems = [];
for (const itemId of selectedIds) {
for (const itemId of args.selectedIds) {
const dataContext = this.sgb.dataView.getItemById(itemId);
for (const itemProp in massUpdateItem) {
if (massUpdateItem.hasOwnProperty(itemProp)) {
const newValue = massUpdateItem[itemProp];
for (const itemProp in args.item) {
if (args.item.hasOwnProperty(itemProp)) {
const newValue = args.item[itemProp];
dataContext[itemProp] = newValue;
}
}
updatedItems.push(dataContext);
}
this.sgb.gridService.updateItems(updatedItems);
} else {
} else if (args.updateType === 'mass') {
// update every rows (full mass update)
for (const itemProp in massUpdateItem) {
if (massUpdateItem.hasOwnProperty(itemProp)) {
this.dataset.forEach(item => item[itemProp] = massUpdateItem[itemProp]);
for (const itemProp in args.item) {
if (args.item.hasOwnProperty(itemProp)) {
this.dataset.forEach(item => item[itemProp] = args.item[itemProp]);
}
}
this.sgb.dataset = this.dataset;
} else {
alert('There was nothing to update, have you selected any rows?');
}
}

Expand Down
Loading