Skip to content

Commit

Permalink
feat(plugin): new Row Based Editing (#1150)
Browse files Browse the repository at this point in the history
* feat(plugin): new Row Based Editing
  • Loading branch information
ghiscoding authored Jan 21, 2024
1 parent f4f64b3 commit 9baf115
Show file tree
Hide file tree
Showing 16 changed files with 663 additions and 145 deletions.
14 changes: 7 additions & 7 deletions packages/aurelia-slickgrid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
"@aurelia/i18n": "latest",
"@aurelia/runtime": "latest",
"@aurelia/runtime-html": "latest",
"@slickgrid-universal/common": "~4.2.0",
"@slickgrid-universal/custom-footer-component": "~4.2.0",
"@slickgrid-universal/empty-warning-component": "~4.2.0",
"@slickgrid-universal/event-pub-sub": "~4.2.0",
"@slickgrid-universal/pagination-component": "~4.2.0",
"@slickgrid-universal/row-detail-view-plugin": "~4.2.0",
"@slickgrid-universal/utils": "~4.2.0",
"@slickgrid-universal/common": "~4.3.0",
"@slickgrid-universal/custom-footer-component": "~4.3.0",
"@slickgrid-universal/empty-warning-component": "~4.3.0",
"@slickgrid-universal/event-pub-sub": "~4.3.0",
"@slickgrid-universal/pagination-component": "~4.3.0",
"@slickgrid-universal/row-detail-view-plugin": "~4.3.0",
"@slickgrid-universal/utils": "~4.3.0",
"dequal": "^2.0.3",
"dompurify": "^3.0.8",
"moment-mini": "^2.29.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,6 @@ export class AureliaSlickgridCustomElement {
@IEventAggregator protected readonly globalEa: IEventAggregator,
protected readonly containerService: ContainerService,
protected readonly translaterService: TranslaterService
// TODO: MB - not sure what this is for
// externalServices: {
// backendUtilityService?: BackendUtilityService,
// collectionService?: CollectionService,
// eventPubSubService: EventPubSubService,
// extensionService?: ExtensionService,
// extensionUtility?: ExtensionUtility,
// filterService?: FilterService,
// gridEventService?: GridEventService,
// gridService?: GridService,
// gridStateService?: GridStateService,
// groupingAndColspanService?: GroupingAndColspanService,
// paginationService?: PaginationService,
// resizerService?: ResizerService,
// rxjs?: RxJsFacade,
// sharedService?: SharedService,
// sortService?: SortService,
// treeDataService?: TreeDataService,
// }
) {
const slickgridConfig = new SlickgridConfig();

Expand Down Expand Up @@ -210,6 +191,7 @@ export class AureliaSlickgridCustomElement {
this.sortService,
this.treeDataService,
this.translaterService,
() => this.gridService
);

this.gridStateService = new GridStateService(this.extensionService, this.filterService, this._eventPubSubService, this.sharedService, this.sortService, this.treeDataService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import {
addToArrayWhenNotExists,
EventSubscription,
OnBeforeRowDetailToggleArgs,
OnRowBackToViewportRangeArgs,
SlickEventData,
SlickEventHandler,
SlickGrid,
Expand Down Expand Up @@ -282,7 +284,7 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
* if it's expanding we will add it to our View Slots reference array if we don't already have it
* or if it's collapsing we will remove it from our View Slots reference array
*/
protected handleOnBeforeRowDetailToggle(_e: Event, args: { grid: SlickGrid; item: any; }) {
protected handleOnBeforeRowDetailToggle(_e: SlickEventData<OnBeforeRowDetailToggleArgs>, args: { grid: SlickGrid; item: any; }) {
// expanding
if (args?.item?.__collapsed) {
// expanding row detail
Expand All @@ -306,7 +308,7 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
}

/** When Row comes back to Viewport Range, we need to redraw the View */
protected async handleOnRowBackToViewportRange(_e: Event, args: {
protected async handleOnRowBackToViewportRange(_e: SlickEventData<OnRowBackToViewportRangeArgs>, args: {
item: any;
rowId: string | number;
rowIndex: number;
Expand Down
22 changes: 11 additions & 11 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@
"@faker-js/faker": "^8.3.1",
"@fnando/sparkline": "^0.3.10",
"@popperjs/core": "^2.11.8",
"@slickgrid-universal/common": "~4.2.0",
"@slickgrid-universal/composite-editor-component": "~4.2.0",
"@slickgrid-universal/custom-tooltip-plugin": "~4.2.0",
"@slickgrid-universal/excel-export": "~4.2.0",
"@slickgrid-universal/graphql": "~4.2.0",
"@slickgrid-universal/odata": "~4.2.0",
"@slickgrid-universal/row-detail-view-plugin": "~4.2.0",
"@slickgrid-universal/rxjs-observable": "~4.2.0",
"@slickgrid-universal/text-export": "~4.2.0",
"@slickgrid-universal/common": "~4.3.0",
"@slickgrid-universal/composite-editor-component": "~4.3.0",
"@slickgrid-universal/custom-tooltip-plugin": "~4.3.0",
"@slickgrid-universal/excel-export": "~4.3.0",
"@slickgrid-universal/graphql": "~4.3.0",
"@slickgrid-universal/odata": "~4.3.0",
"@slickgrid-universal/row-detail-view-plugin": "~4.3.0",
"@slickgrid-universal/rxjs-observable": "~4.3.0",
"@slickgrid-universal/text-export": "~4.3.0",
"aurelia": "latest",
"aurelia-slickgrid": "workspace:*",
"bootstrap": "^5.3.2",
"dompurify": "^3.0.8",
"flatpickr": "^4.6.13",
"i18next": "^23.7.13",
"i18next": "^23.7.17",
"i18next-fetch-backend": "^5.0.2",
"moment-mini": "^2.29.4",
"rxjs": "^7.8.1"
Expand All @@ -83,7 +83,7 @@
"clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "^12.0.2",
"copyfiles": "^2.4.1",
"css-loader": "^6.9.0",
"css-loader": "^6.9.1",
"dotenv-webpack": "^8.0.1",
"fetch-jsonp": "^1.3.0",
"font-awesome": "^4.7.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/demo/src/assets/i18n/en/aurelia-slickgrid.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@
"START": "Start",
"TASK_X": "Task {{x}}",
"TITLE": "Title",
"TRUE": "True"
"TRUE": "True",
"X_DAY_PLURAL": "{{x}} day{{plural}}",
"RBE_BTN_UPDATE": "Update the current row",
"RBE_BTN_CANCEL": "Cancel changes of the current row"
}
5 changes: 4 additions & 1 deletion packages/demo/src/assets/i18n/fr/aurelia-slickgrid.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,8 @@
"TASK_X": "Tâche {{x}}",
"TITLE": "Titre",
"TITLE.NAME": "Nom du Titre",
"TRUE": "Vrai"
"TRUE": "Vrai",
"X_DAY_PLURAL": "{{x}} journée{{plural}}",
"RBE_BTN_UPDATE": "Mettre à jour la ligne actuelle",
"RBE_BTN_CANCEL": "Annuler la ligne actuelle"
}
8 changes: 4 additions & 4 deletions packages/demo/src/examples/slickgrid/example24.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ export class Example24 {
onCommand: (_e, args) => this.executeCommand(_e, args),
onOptionSelected: (_e, args) => {
// change "Completed" property with new option selected from the Cell Menu
const dataContext = args && args.dataContext;
if (dataContext && dataContext.hasOwnProperty('completed')) {
const dataContext = args?.dataContext;
if (dataContext?.hasOwnProperty('completed')) {
dataContext.completed = args.item.option;
this.aureliaGrid.gridService.updateItem(dataContext);
}
Expand All @@ -319,7 +319,7 @@ export class Example24 {
};
}

executeCommand(_e: Event, args: any) {
executeCommand(_e: any, args: any) {
const command = args.command;
const dataContext = args.dataContext;

Expand Down Expand Up @@ -491,7 +491,7 @@ export class Example24 {
onCommand: ((_e, args) => this.executeCommand(_e, args)),

// subscribe to Context Menu onOptionSelected event (or use the action callback on each option)
onOptionSelected: ((_e, args) => {
onOptionSelected: ((_e: any, args: any) => {
// change Priority
const dataContext = args && args.dataContext;
if (dataContext?.hasOwnProperty('priority')) {
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/examples/slickgrid/example33.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ export class Example33 {
return tmpArray;
}

executeCommand(_e: Event, args: MenuCommandItemCallbackArgs) {
executeCommand(_e: any, args: MenuCommandItemCallbackArgs) {
// const columnDef = args.column;
const command = args.command;
const dataContext = args.dataContext;
Expand Down
77 changes: 77 additions & 0 deletions packages/demo/src/examples/slickgrid/example35.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<h2>
Example 35: Row Based Editing
<span class="float-end">
<a style="font-size: 18px"
target="_blank"
href="https://github.com/ghiscoding/aurelia-slickgrid/blob/master/src/examples/slickgrid/example35.ts">
<span class="fa fa-link"></span> code
</a>
</span>
</h2>

<div class="subtitle">
<ul>
<li>
The Row Based Edit plugin allows you to edit either a single or multiple
specific rows at a time, while disabling the rest of the grid rows.
</li>
<li>
Editedable rows, as well as modified cells are highlighted with a
different color, which you can customize using css variables (see
<a
target="_blank"
href="https://github.com/ghiscoding/aurelia-slickgrid/blob/master/src/examples/slickgrid/example35.scss"
>
example35.scss </a
>)
</li>
<li>
Modifications are kept track of and if the cancel button is pressed, all
modifications are rolled back.
</li>
<li>
If the save button is pressed, a custom "onBeforeRowUpdated" callback is called, which you can use to save the data with your backend.<br />
The callback needs to return a Promise&lt;boolean&gt; and if the promise resolves to true, then the row will be updated, otherwise it will be cancelled and stays in edit mode.
You can try out the later by defining a Duration value <b>larger than 40</b>.
<br />
<small><span class="has-text-danger">NOTE:</span> You can also combine this with e.g. Batch Editing like shown <a href="#/example30">in Example 30</a></small>
</li>
<li>
This example additionally uses the ExcelCopyBuffer Plugin, which you can see also in Slickgrid-Universal
<a href="https://ghiscoding.github.io/slickgrid-universal/#/example19">example 19</a>.
The example defines a rule that pastes in the first column are prohibited. In combination with the Row Based Editing Plugin though, this rule gets enhanced with the fact
that only the edited rows are allowed to be pasted into, while still respecting the original rule.
</li>
</ul>
</div>

<section>
<div class="row mb-4">
<div class="col-sm-8">
<button
class="btn btn-outline-secondary btn-sm"
data-test="single-multi-toggle"
click.trigger="toggleSingleMultiRowEdit()"
>
Toggle Single/Multi Row Edit
</button>
<button class="btn btn-outline-secondary btn-sm" data-test="toggle-language" click.trigger="switchLanguage()">
<i class="fa fa-language"></i>
Switch Language for Action column buttons
</button>
<label>Locale:</label>
<span style="font-style: italic; width: 70px;" data-test="selected-locale">
${selectedLanguage + '.json'}
</span>
</div>

<div class="col-sm-4" class.bind="statusClass">
<strong>Status: </strong>
<span data-test="fetch-result" textcontent.bind="fetchResult"></span>
</div>
</div>
</section>

<aurelia-slickgrid grid-id="grid35" column-definitions.bind="columnDefinitions" grid-options.bind="gridOptions"
dataset.bind="dataset" instances.bind="aureliaGrid">
</aurelia-slickgrid>
18 changes: 18 additions & 0 deletions packages/demo/src/examples/slickgrid/example35.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
:root {
// turn on/off the following variables to see the difference in styling

// --slick-row-based-edit-editmode-bgcolor: rgb(82, 235, 158);
// --slick-row-based-edit-editmode-hover-bgcolor: cyan;
// --slick-row-based-edit-unsaved-cell-bgcolor: rgb(190, 114, 127);
// --slick-row-based-edit-editmode-active-bgcolor: rgb(82, 235, 158);
// --slick-row-based-edit-editmode-active-hover-bgcolor: cyan;
}

.alert {
padding: 8px;
margin-bottom: 10px
}

.status-container {
min-height: 50px;
}
Loading

0 comments on commit 9baf115

Please sign in to comment.