Skip to content

Commit bd9cdf2

Browse files
committed
Merge remote-tracking branch 'IgniteUI/master'
2 parents c73cb34 + 1160e02 commit bd9cdf2

File tree

3 files changed

+111
-9
lines changed

3 files changed

+111
-9
lines changed

src/igniteui.angular2.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ export class IgControlBase<Model> implements DoCheck {
253253
jQuery.ui[this._widgetName].prototype.options.hasOwnProperty(name) &&
254254
jQuery(this._el).data(this._widgetName)) {
255255
jQuery(this._el)[this._widgetName]("option", name, value);
256+
if(name === "dataSource" && this instanceof IgGridBase) {
257+
this._dataSource = jQuery.extend(true, [], value);
258+
}
256259
}
257260
}
258261
}
@@ -430,14 +433,14 @@ export class IgGridBase<Model> extends IgControlBase<Model> implements AfterCont
430433
}
431434

432435
ngAfterContentInit() {
433-
if (this._columns.length) {
436+
if (this._columns && this._columns.length) {
434437
if (this._config) {
435438
this._config["columns"] = this._columns.map((c) => c._settings);
436439
} else {
437440
this._opts["columns"] = this._columns.map((c) => c._settings);
438441
}
439442
}
440-
if (this._features.length) {
443+
if (this._features && this._features.length) {
441444
if (this._config) {
442445
this._config["features"] = this._features.map((c) => c.initSettings);
443446
} else {
@@ -703,13 +706,15 @@ export class IgComboComponent extends IgControlBase<IgCombo> implements ControlV
703706
super.ngOnInit();
704707
jQuery(this._el).on(this._widgetName.toLowerCase() + "selectionchanged", function (evt, ui) {
705708
var items = ui.items;
706-
if (items.length > 0) {
709+
if (items.length > 0 && that._model) {
707710
that._model.viewToModelUpdate(items[0].data[that._config.valueKey]);
708711
}
709712
});
710713
this._dataSource = jQuery.extend(true, [], this._config.dataSource);
711714
//manually call writeValue, because the LifeCycle has been changed and writeValue is executed before ngOnInit
712-
this.writeValue(this._model.value);
715+
if (this._model) {
716+
this.writeValue(this._model.value);
717+
}
713718
}
714719
writeValue(value) {
715720
if (!!jQuery(this._el).data(this._widgetName)) {
@@ -740,11 +745,14 @@ export class IgComboComponent extends IgControlBase<IgCombo> implements ControlV
740745

741746
//check for changes in collection
742747
this._changes = this._differ.diff(this._config.dataSource);
743-
if (this._config.dataSource.length !== this._dataSource.length) {
748+
if (this._config.dataSource && this._config.dataSource.length !== this._dataSource.length) {
744749
this._dataSource = jQuery.extend(true, [], this._config.dataSource);
745750
if (this._changes) {
746751
this._changes.forEachAddedItem(r => element.data("igCombo").dataBind());
747-
this._changes.forEachRemovedItem(r => element.data("igCombo").dataBind())
752+
this._changes.forEachRemovedItem(r => element.data("igCombo").dataBind());
753+
if (this.model && this.model.value) {
754+
this.writeValue(this.model.value);
755+
}
748756
}
749757
}
750758

tests/unit/igcombo/combo.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ export function main() {
3131
});
3232
});
3333

34+
it('should initialize ig-combo without ngModel', (done) => {
35+
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [changeDetectionInterval]="cdi"></ig-combo></div>';
36+
TestBed.overrideComponent(TestComponent, {
37+
set: {
38+
template: template
39+
}
40+
});
41+
TestBed.compileComponents().then(() => {
42+
let fixture = TestBed.createComponent(TestComponent);
43+
fixture.detectChanges();
44+
expect(fixture.debugElement.componentInstance.viewChild instanceof Infragistics.IgComboComponent)
45+
.toBe(true);
46+
done();
47+
});
48+
});
49+
3450
it('should be updated correctly if the ngModel value is updated', (done) => {
3551
var template = '<div><ig-combo [(widgetId)]="comboID" [(options)]="options" [changeDetectionInterval]="cdi" [(ngModel)]="combo.value1"></ig-combo></div>';
3652
TestBed.overrideComponent(TestComponent, {
@@ -94,6 +110,29 @@ export function main() {
94110
}, 10);
95111
});
96112
});
113+
114+
it('should apply the model if there is a new data assigned', (done) => {
115+
var template = '<div><ig-combo [(widgetId)]="comboID" [valueKey]="\'ProductID\'" [textKey]="\'ProductName\'" [changeDetectionInterval]="cdi" [(dataSource)]="data" [(ngModel)]="combo.value1"></ig-combo></div>';
116+
TestBed.overrideComponent(TestComponent, {
117+
set: {
118+
template: template
119+
}
120+
});
121+
TestBed.compileComponents().then(() => {
122+
let fixture = TestBed.createComponent(TestComponent);
123+
fixture.detectChanges();
124+
fixture.componentInstance.data = fixture.componentInstance.northwind;
125+
126+
setTimeout(function () {
127+
fixture.detectChanges();
128+
129+
expect($("#combo1").igCombo("value")).toBe(fixture.componentInstance.combo.value1);
130+
expect($("#combo1").val())
131+
.toBe(fixture.componentInstance.northwind[fixture.componentInstance.combo.value1 - 1].ProductName);
132+
done();
133+
}, 10);
134+
});
135+
});
97136
});
98137
}
99138

@@ -107,6 +146,7 @@ class TestComponent {
107146
public combo: any;
108147
private comboID: string
109148
private cdi = 10;
149+
public data: Array<any> = [];
110150
@ViewChild(Infragistics.IgComboComponent) public viewChild: Infragistics.IgComboComponent;
111151

112152
constructor() {

tests/unit/iggrid/grid.spec.ts

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,33 @@ export function main() {
362362
}, 10);
363363
});
364364
});
365+
366+
it('should allow filtering after new data is applied', (done) => {
367+
var template = '<div><ig-grid [(widgetId)]="gridID" [(options)]="opts2" [(dataSource)]="data1"></ig-grid></div>';
368+
TestBed.overrideComponent(TestComponent, {
369+
set: {
370+
template: template
371+
}
372+
});
373+
TestBed.compileComponents().then(() => {
374+
let fixture = TestBed.createComponent(TestComponent);
375+
fixture.detectChanges();
376+
expect(fixture.debugElement.componentInstance.viewChild instanceof Infragistics.IgGridComponent)
377+
.toBe(true);
378+
fixture.componentInstance.data1 = [
379+
{"Id":"4", "Date":"\/Date(1235088000000)\/"},
380+
{"Id":"5", "Date":"\/Date(1250809200000)\/"},
381+
{"Id":"6", "Date":"\/Date(1335394800000)\/"}
382+
];
383+
setTimeout(() => {
384+
fixture.detectChanges();
385+
$(fixture.debugElement.nativeElement).find("#grid1").igGridFiltering("filter", ([{fieldName: "Date", expr: "\/Date(704678400000)\/", cond: "notOn"}]));
386+
expect($(fixture.debugElement.nativeElement).find("#grid1_container .ui-iggrid-results").text())
387+
.toBe("3 matching records");
388+
done();
389+
}, 500);
390+
});
391+
});
365392
});
366393
}
367394

@@ -372,8 +399,10 @@ export function main() {
372399
class TestComponent {
373400
private opts: any;
374401
public opts1: any;
402+
public opts2: any;
375403
private gridID: string;
376404
public data: Array<any>;
405+
public data1: Array<any>;
377406
private cdi: number;
378407
public pi: number;
379408
private firedEvent: any;
@@ -391,16 +420,21 @@ class TestComponent {
391420
{ "Id": 1, "Name": "John Smith", "Age": 45, "HireDate": "\/Date(704678400000)\/" },
392421
{ "Id": 2, "Name": "Mary Johnson", "Age": 32, "HireDate": "\/Date(794678400000)\/" },
393422
{ "Id": 3, "Name": "Bob Ferguson", "Age": 27, "HireDate": "\/Date(834678400000)\/" }
394-
]
395-
this.opts = {
423+
];
424+
this.data1 = [
425+
{"Id":"1", "Date":"\/Date(1250809200000)\/"},
426+
{"Id":"2", "Date":"\/Date(1335394800000)\/"},
427+
{"Id":"3", "Date":"\/Date(1235088000000)\/"}
428+
];
429+
this.opts = {
396430
primaryKey: "Id",
397431
dataSource: this.data,
398432
autoCommit: true,
399433
features: [
400434
{ name: "Updating" }
401435
]
402436
};
403-
437+
404438
this.opts1 = {
405439
dataSource: this.data,
406440
height: "300px",
@@ -417,6 +451,26 @@ class TestComponent {
417451
{ name: "Updating" }
418452
]
419453
};
454+
455+
this.opts2 = {
456+
width: "100%",
457+
height: "400px",
458+
autoCommit: true,
459+
autoGenerateColumns: false,
460+
columns: [
461+
{ key: "Id", headerText: "ID", width: "20%", dataType: "string" },
462+
{ key: "Date", headerText: "Date", dataType: "date", width: "80%", format: "dd/MM/yyyy" },
463+
],
464+
primaryKey: "Id",
465+
features: [
466+
{
467+
name: "Filtering",
468+
type: "local",
469+
mode: "simple",
470+
filterDialogContainment: "window"
471+
}
472+
]
473+
};
420474
}
421475

422476
public cellClickHandler(evt) {

0 commit comments

Comments
 (0)