Skip to content

Commit 5ced14c

Browse files
committed
Improve declaring columns and features as nested directives
1 parent d7fb911 commit 5ced14c

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

samples/igGrid-ComplexOpts/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class AppComponent {
2121
private isReadOnly: boolean = true;
2222
private cs: Array<any> = [{columnKey: "ProductID", readOnly: this.isReadOnly}];
2323
private pi: number = 0;
24+
private idHeaderText: string = "Id";
2425
private pages: Array<number> = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
2526

2627
constructor() {

samples/igGrid-ComplexOpts/igGrid-ComplexOpts.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ <h1 class="push-down-md"><a href="http://igniteui.com/grid/overview" target="_bl
7171
<!-- Ignite UI Required Combined JavaScript Files -->
7272
<script src="http://cdn-na.infragistics.com/igniteui/latest/js/infragistics.core.js"></script>
7373
<script src="http://cdn-na.infragistics.com/igniteui/latest/js/infragistics.lob.js"></script>
74+
7475
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.js"></script>
7576
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
7677
<script>

samples/igGrid-ComplexOpts/igGrid-ComplexOptsTemplate.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<column [key]="'ProductName'" [headerText]="'Product Name'" [width]="'250px'" [dataType]="'string'"></column>
66
<column [key]="'QuantityPerUnit'" [headerText]="'Quantity per unit'" [width]="'250px'" [dataType]="'string'"></column>
77
<column [key]="'UnitPrice'" [headerText]="'Unit Price'" [width]="'100px'" [dataType]="'number'"></column>
8-
<feature [name]="'Updating'" [(columnSettings)]="cs"></feature>
98
<feature [name]="'Paging'" [(currentPageIndex)]="pi" [pageSize]="'2'"></feature>
109
</ig-grid>
1110

@@ -14,6 +13,8 @@
1413
<select [(ngModel)]="pi" name="pageIndex">
1514
<option *ngFor="let i of pages">{{i}}</option>
1615
</select>
16+
<br>
17+
<label for="headerText">First column header text:</label><input name="headerText" [(ngModel)]="idHeaderText">{{idHeaderText}}
1718
</div>
1819

1920
</div>

src/igniteui.angular2.ts

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,54 @@ module IgUtil {
6565
}
6666
return options;
6767
}
68+
69+
export function extractAllGridColumnProperties() {
70+
return ['headerText', 'key', 'formatter', 'format', 'dataType', 'width', 'hidden', 'template', 'unbound', 'group', 'rowspan', 'formula', 'unboundValues', 'unboundValuesUpdateMode', 'headerCssClass', 'columnCssClass'];
71+
}
6872
}
6973

7074
@Directive({
7175
selector: 'column',
72-
inputs: ['headerText', 'key', 'formatter', 'format', 'dataType', 'width', 'hidden', 'template', 'unbound', 'group', 'rowspan', 'formula', 'unboundValues', 'unboundValuesUpdateMode', 'headerCssClass', 'columnCssClass']
76+
inputs: IgUtil.extractAllGridColumnProperties()
7377
})
74-
export class Column {}
78+
export class Column {
79+
private _settings: any = {};
80+
private _el: any;
81+
82+
constructor(el: ElementRef) {
83+
this._el = el;
84+
let self = this;
85+
let i, settings = IgUtil.extractAllGridColumnProperties();
86+
for(i = 0; i < settings.length; i++) {
87+
Object.defineProperty(self, settings[i], {
88+
set: self.createColumnsSetter(settings[i]),
89+
get: self.createColumnsGetter(settings[i]),
90+
enumerable: true,
91+
configurable: true
92+
});
93+
}
94+
}
95+
96+
createColumnsSetter(name) {
97+
return function (value) {
98+
let grid = jQuery(this._el.nativeElement.parentElement).find("table[role='grid']");
99+
this._settings[name] = value;
100+
101+
if (jQuery.ui["igGrid"] &&
102+
jQuery.ui["igGrid"].prototype.options &&
103+
jQuery.ui["igGrid"].prototype.options.hasOwnProperty("columns") &&
104+
grid.data("igGrid")) {
105+
grid["igGrid"]("option", "columns", this._settings);
106+
}
107+
}
108+
}
109+
110+
createColumnsGetter(name) {
111+
return function () {
112+
return this._settings[name];
113+
}
114+
}
115+
}
75116

76117
@Directive({
77118
selector: 'feature',
@@ -81,12 +122,10 @@ export class Column {}
81122
export class Feature {
82123
private _el: any;
83124
private _settings: any = {};
84-
@Input() public name: string;
85-
86-
constructor(el: ElementRef) {
87-
this._el = el;
125+
@Input() set name(name: string) {
126+
this._settings["name"] = name;
88127
var self = this;
89-
let featureName = "igGrid" + this.name;
128+
let featureName = "igGrid" + name;
90129
for (var setting in jQuery.ui[featureName].prototype.options) {
91130
Object.defineProperty(self, setting, {
92131
set: self.createFeatureSetter(setting),
@@ -97,8 +136,12 @@ export class Feature {
97136
}
98137
}
99138

100-
ngOnInit() {
101-
139+
get name():string {
140+
return this._settings["name"];
141+
}
142+
143+
constructor(el: ElementRef) {
144+
this._el = el;
102145
}
103146

104147
createFeatureSetter(name) {
@@ -396,10 +439,10 @@ export class IgGridBase<Model> extends IgControlBase<Model> implements AfterCont
396439

397440
ngAfterContentInit() {
398441
if (this._columns.length) {
399-
this._opts["columns"] = this._columns.map((c) => c);
442+
this._opts["columns"] = this._columns.map((c) => c._settings);
400443
}
401444
if (this._features.length) {
402-
this._opts["features"] = this._features.map((c) => c);
445+
this._opts["features"] = this._features.map((c) => c._settings);
403446
}
404447
super.ngOnInit();
405448
}

0 commit comments

Comments
 (0)