Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 6bf4ed9

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
Add more inline editors. changed all date formatters and filterCondition to use columnDef type field for knowing which date format to use. Exposed grid and dataview object at the component level to get access to all Slickgrid events.
1 parent c10b4aa commit 6bf4ed9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+551
-246
lines changed

.angular-cli.json

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"prefix": "app",
2121
"styles": [
2222
"../node_modules/bootstrap/dist/css/bootstrap.css",
23+
"../node_modules/flatpickr/dist/flatpickr.min.css",
2324
"../node_modules/font-awesome/css/font-awesome.css",
2425
"app/slickgrid-custom-variables.scss",
2526
"styles.scss"
@@ -28,24 +29,7 @@
2829
"../node_modules/jquery/dist/jquery.js",
2930
"../node_modules/bootstrap/dist/js/bootstrap.js",
3031
"../node_modules/slickgrid/lib/jquery-ui-1.11.3.js",
31-
"../node_modules/slickgrid/lib/jquery.event.drag-2.3.0.js",
32-
"../node_modules/slickgrid/slick.core.js",
33-
"../node_modules/slickgrid/slick.dataview.js",
34-
"../node_modules/slickgrid/slick.grid.js",
35-
"../node_modules/slickgrid/slick.dataview.js",
36-
"../node_modules/slickgrid/plugins/slick.autotooltips.js",
37-
"../node_modules/slickgrid/plugins/slick.cellcopymanager.js",
38-
"../node_modules/slickgrid/plugins/slick.cellexternalcopymanager.js",
39-
"../node_modules/slickgrid/plugins/slick.cellrangedecorator.js",
40-
"../node_modules/slickgrid/plugins/slick.cellrangeselector.js",
41-
"../node_modules/slickgrid/plugins/slick.cellselectionmodel.js",
42-
"../node_modules/slickgrid/plugins/slick.checkboxselectcolumn.js",
43-
"../node_modules/slickgrid/plugins/slick.headerbuttons.js",
44-
"../node_modules/slickgrid/plugins/slick.headermenu.js",
45-
"../node_modules/slickgrid/plugins/slick.rowmovemanager.js",
46-
"../node_modules/slickgrid/plugins/slick.rowselectionmodel.js",
47-
"../node_modules/slickgrid/controls/slick.columnpicker.js",
48-
"../node_modules/slickgrid/controls/slick.pager.js"
32+
"../node_modules/slickgrid/lib/jquery.event.drag-2.3.0.js"
4933
],
5034
"environmentSource": "environments/environment.ts",
5135
"environments": {

src/app/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GridOdataService } from './modules/angular-slickgrid/services';
1+
import { GridOdataService, ResizerService } from './modules/angular-slickgrid/services';
22
import { AppRoutingRoutingModule } from './app-routing.module';
33
import { BrowserModule } from '@angular/platform-browser';
44
import { HttpClientModule } from '@angular/common/http';
@@ -33,7 +33,7 @@ import { AngularSlickgridModule } from './modules/angular-slickgrid/modules/angu
3333
HttpClientModule,
3434
AngularSlickgridModule
3535
],
36-
providers: [GridOdataService],
36+
providers: [GridOdataService, ResizerService],
3737
bootstrap: [AppComponent]
3838
})
3939
export class AppModule { }

src/app/examples/grid-editor.component.html

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,28 @@
33
<h2>{{title}}</h2>
44
<div class="subtitle" [innerHTML]="subTitle"></div>
55

6-
<angular-slickgrid gridId="grid2"
7-
[columnDefinitions]="columnDefinitions"
8-
[gridOptions]="gridOptions"
9-
[dataset]="dataset">
10-
</angular-slickgrid>
11-
</div>
6+
<div class="col-sm-4">
7+
<label>autoEdit setting</label>
8+
<br/>
9+
<span id="radioAutoEdit">
10+
<label class="radio-inline control-label" for="radioTrue">
11+
<input type="radio" name="inlineRadioOptions" id="radioTrue" checked [value]="isAutoEdit" (change)="setAutoEdit(true)"> ON (single-click)
12+
</label>
13+
<label class="radio-inline control-label" for="radioFalse">
14+
<input type="radio" name="inlineRadioOptions" id="radioFalse" [value]="isAutoEdit" (change)="setAutoEdit(false)"> OFF (double-click)
15+
</label>
16+
</span>
17+
</div>
18+
19+
<div class="col-sm-8">
20+
<div class="alert alert-info" *ngIf="updatedObject">
21+
<strong>Update Object:</strong> {{updatedObject | json}}
22+
</div>
23+
</div>
24+
25+
<div class="col-sm-12">
26+
<angular-slickgrid gridId="grid2" (dataviewChanged)="dataviewReady($event)" (gridChanged)="gridReady($event)"
27+
[columnDefinitions]="columnDefinitions" [gridOptions]="gridOptions" [dataset]="dataset">
28+
</angular-slickgrid>
29+
</div>
30+
</div>
Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, Input, OnInit } from '@angular/core';
22
import { Editors, Formatters } from './../modules/angular-slickgrid';
3+
import { GridExtraUtils, ResizerService } from './../modules/angular-slickgrid/services';
34
import { OnCellClickArgs, Column, FieldType, Formatter, GridOption } from './../modules/angular-slickgrid/models';
45

56
@Component({
6-
templateUrl: './grid-formatter.component.html'
7+
templateUrl: './grid-editor.component.html'
78
})
89
export class GridEditorComponent implements OnInit {
910
title = 'Example 4: Editors';
@@ -12,11 +13,27 @@ export class GridEditorComponent implements OnInit {
1213
columnDefinitions: Column[];
1314
gridOptions: GridOption;
1415
dataset: any[];
16+
isAutoEdit: boolean = true;
17+
updatedObject: any;
18+
gridObj: any;
19+
dataviewObj: any;
20+
21+
constructor(private resizer: ResizerService) {}
1522

1623
ngOnInit(): void {
1724
this.columnDefinitions = [
18-
{ id: 'id', field: 'id',
19-
formatter: Formatters.editPencil,
25+
{
26+
id: 'edit', field: 'id',
27+
formatter: Formatters.editIcon,
28+
maxWidth: 30,
29+
onCellClick: (args: OnCellClickArgs) => {
30+
console.log(args);
31+
console.log(this);
32+
}
33+
},
34+
{
35+
id: 'delete', field: 'id',
36+
formatter: Formatters.deleteIcon,
2037
maxWidth: 30,
2138
onCellClick: (args: OnCellClickArgs) => {
2239
console.log(args);
@@ -25,10 +42,10 @@ export class GridEditorComponent implements OnInit {
2542
},
2643
{ id: 'title', name: 'Title', field: 'title', sortable: true, type: FieldType.string, editor: Editors.longText },
2744
{ id: 'duration', name: 'Duration (days)', field: 'duration', sortable: true, type: FieldType.number, editor: Editors.text },
28-
{ id: 'complete', name: '% Complete', field: 'percentComplete', formatter: Formatters.percentCompleteBar, type: FieldType.number, editor: Editors.integer, sortable: true },
29-
{ id: 'start', name: 'Start', field: 'start', formatter: Formatters.dateIso, sortable: true, type: FieldType.dateIso, editor: Editors.date },
45+
{ id: 'complete', name: '% Complete', field: 'percentComplete', formatter: Formatters.percentCompleteBar, type: FieldType.number, editor: Editors.integer },
46+
{ id: 'start', name: 'Start', field: 'start', formatter: Formatters.dateIso, sortable: true, type: FieldType.date, editor: Editors.date },
3047
{ id: 'finish', name: 'Finish', field: 'finish', formatter: Formatters.dateIso, sortable: true, type: FieldType.date },
31-
{ id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', formatter: Formatters.checkmark, type: FieldType.number, sortable: true }
48+
{ id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', formatter: Formatters.checkmark, type: FieldType.number, editor: Editors.checkbox }
3249
];
3350

3451
this.gridOptions = {
@@ -37,20 +54,21 @@ export class GridEditorComponent implements OnInit {
3754
sidePadding: 15
3855
},
3956
editable: true,
57+
enableColumnPicker: true,
4058
enableCellNavigation: true,
4159
asyncEditorLoading: false,
42-
autoEdit: true
60+
autoEdit: this.isAutoEdit
4361
};
4462

4563
// mock a dataset
46-
this.dataset = [];
47-
for (let i = 0; i < 5; i++) {
64+
let mockedDataset = [];
65+
for (let i = 0; i < 1000; i++) {
4866
const randomYear = 2000 + Math.floor(Math.random() * 10);
4967
const randomMonth = Math.floor(Math.random() * 11);
5068
const randomDay = Math.floor((Math.random() * 29));
5169
const randomPercent = Math.round(Math.random() * 100);
5270

53-
this.dataset[i] = {
71+
mockedDataset[i] = {
5472
id: i,
5573
title: 'Task ' + i,
5674
duration: Math.round(Math.random() * 100) + '',
@@ -61,5 +79,36 @@ export class GridEditorComponent implements OnInit {
6179
effortDriven: (i % 5 === 0)
6280
};
6381
}
82+
this.dataset = mockedDataset;
83+
}
84+
85+
gridReady(grid) {
86+
this.gridObj = grid;
87+
88+
grid.onCellChange.subscribe((e, args) => {
89+
console.log('onCellChange', args);
90+
this.updatedObject = args.item;
91+
this.resizer.resizeGrid(this.gridObj, this.gridOptions, 10);
92+
});
93+
grid.onClick.subscribe((e, args) => {
94+
const column = GridExtraUtils.getColumnDefinitionAndData(args);
95+
console.log('onClick', args, column);
96+
if (column.columnDef.id === 'delete') {
97+
if (confirm('Are you sure?')) {
98+
this.dataviewObj.deleteItem(column.dataContext.id);
99+
this.dataviewObj.refresh();
100+
}
101+
}
102+
});
103+
104+
}
105+
dataviewReady(dataview) {
106+
this.dataviewObj = dataview;
107+
}
108+
109+
setAutoEdit(isAutoEdit) {
110+
this.isAutoEdit = isAutoEdit;
111+
this.gridObj.setOptions({ autoEdit: isAutoEdit }); // change the grid option dynamically
112+
return true;
64113
}
65114
}

src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1+
// import 3rd party vendor libs
2+
import 'slickgrid/lib/jquery-ui-1.11.3';
3+
import 'slickgrid/lib/jquery.event.drag-2.3.0';
4+
import 'slickgrid/slick.core';
5+
import 'slickgrid/slick.dataview';
6+
import 'slickgrid/slick.grid';
7+
import 'slickgrid/slick.dataview';
8+
import 'slickgrid/plugins/slick.autotooltips';
9+
import 'slickgrid/plugins/slick.cellcopymanager';
10+
import 'slickgrid/plugins/slick.cellexternalcopymanager';
11+
import 'slickgrid/plugins/slick.cellrangedecorator';
12+
import 'slickgrid/plugins/slick.cellrangeselector';
13+
import 'slickgrid/plugins/slick.cellselectionmodel';
14+
import 'slickgrid/plugins/slick.checkboxselectcolumn';
15+
import 'slickgrid/plugins/slick.headerbuttons';
16+
import 'slickgrid/plugins/slick.headermenu';
17+
import 'slickgrid/plugins/slick.rowmovemanager';
18+
import 'slickgrid/plugins/slick.rowselectionmodel';
19+
import 'slickgrid/controls/slick.columnpicker';
20+
import 'slickgrid/controls/slick.pager';
121
import { castToPromise } from './../services/utilities';
222
import { Column, ColumnFilters, FormElementType, GridOption } from './../models';
3-
import { AfterViewInit, Component, Injectable, Input, OnInit } from '@angular/core';
23+
import { AfterViewInit, Component, EventEmitter , Injectable, Input, Output, OnInit } from '@angular/core';
424
import { FilterService, GridEventService, SortService, ResizerService } from './../services';
525
import { GlobalGridOptions } from './../global-grid-options';
626

@@ -32,8 +52,9 @@ export class AngularSlickgridComponent implements AfterViewInit, OnInit {
3252
gridHeightString: string;
3353
gridWidthString: string;
3454
showPagination = false;
35-
onFilter = new Slick.Event();
3655

56+
@Output() dataviewChanged = new EventEmitter<any>();
57+
@Output() gridChanged = new EventEmitter<any>();
3758
@Input() gridId: string;
3859
@Input() columnDefinitions: Column[];
3960
@Input() gridOptions: GridOption;
@@ -68,6 +89,8 @@ export class AngularSlickgridComponent implements AfterViewInit, OnInit {
6889

6990
this.grid = new Slick.Grid(`#${this.gridId}`, this._dataView, this.columnDefinitions, this._gridOptions);
7091
this.grid.setSelectionModel(new Slick.RowSelectionModel());
92+
this.gridChanged.emit(this.grid);
93+
this.dataviewChanged.emit(this._dataView);
7194

7295
if (this._gridOptions.enableColumnPicker) {
7396
const columnpicker = new Slick.Controls.ColumnPicker(this.columnDefinitions, this.grid, this._gridOptions);
@@ -145,7 +168,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnInit {
145168
grid.autosizeColumns();
146169
}
147170
} else {
148-
this.resizer.resizeGrid(grid, options, { height: this.gridHeight, width: this.gridWidth });
171+
this.resizer.resizeGrid(grid, options, 0, { height: this.gridHeight, width: this.gridWidth });
149172
}
150173
}
151174

@@ -186,10 +209,8 @@ export class AngularSlickgridComponent implements AfterViewInit, OnInit {
186209
}
187210
if (this._gridOptions.enableAutoResize) {
188211
// resize the grid inside a slight timeout, in case other DOM element changed prior to the resize (like a filter/pagination changed)
189-
setTimeout(() => {
190-
this.resizer.resizeGrid(this.grid, this._gridOptions);
212+
this.resizer.resizeGrid(this.grid, this._gridOptions, 10);
191213
// this.grid.autosizeColumns();
192-
});
193214
}
194215
}
195216
}

src/app/modules/angular-slickgrid/editors/checkboxEditor.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
// import flatpickr from 'flatpickr';
2-
// import 'flatpickr/dist/flatpickr.min.css';
31
import $ from 'jquery';
42
import { Editor, KeyCode } from './../models';
53

64
/*
75
* An example of a 'detached' editor.
8-
* The UI is added onto document BODY and .position(), .show() and .hide() are implemented.
96
* KeyDown events are also handled to provide handling for Tab, Shift-Tab, Esc and Ctrl-Enter.
107
*/
118
export class CheckboxEditor implements Editor {
12-
$input;
13-
$wrapper;
14-
defaultValue;
9+
$input: any;
10+
defaultValue: boolean;
1511

1612
constructor(private args: any) {
1713
this.init();
@@ -23,15 +19,15 @@ export class CheckboxEditor implements Editor {
2319
this.$input.focus();
2420
}
2521

26-
destroy() {
22+
destroy(): void {
2723
this.$input.remove();
2824
}
2925

30-
focus() {
26+
focus(): void {
3127
this.$input.focus();
3228
}
3329

34-
loadValue(item) {
30+
loadValue(item: any) {
3531
this.defaultValue = !!item[this.args.column.field];
3632
if (this.defaultValue) {
3733
this.$input.prop('checked', true);
@@ -44,11 +40,11 @@ export class CheckboxEditor implements Editor {
4440
this.$input.prop('checked', !this.$input.prop('checked'));
4541
}
4642

47-
serializeValue() {
43+
serializeValue(): boolean {
4844
return this.$input.prop('checked');
4945
}
5046

51-
applyValue(item, state) {
47+
applyValue(item: any, state: any) {
5248
item[this.args.column.field] = state;
5349
}
5450

0 commit comments

Comments
 (0)