Skip to content

Commit db3ac19

Browse files
committed
Notify grid data is changed when setting it through option
1 parent fa08a89 commit db3ac19

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

src/igniteui.angular2.ts

Lines changed: 5 additions & 2 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 {

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)