|
@Component({
selector: 'app-root',
template: `<ejs-grid #grid [dataSource]='data' [allowSelection]='false' [enableHover]='false'
height='300' (queryCellInfo)='queryCellInfo($event)' (dataBound)='dataBound($event)'>
<e-columns>
. . .
<e-column field='Net' headerText='Net' width='120' format='N2' textAlign='Right'></e-column>
<e-column field='Rating' headerText='Rating' width='120'></e-column>
</e-columns>
</ejs-grid>`
})
export class AppComponent extends Subject<DataStateChangeEventArgs> implements OnInit {
public data: Object[] = [];
@ViewChild('grid')
public grid: GridComponent;
ngOnInit() {
this.getTradeData(20).then((e: any) => {
this.data = e;
});
}
. . .
dataBound(args: any): void {
clearTimeout(clrIntervalFun1);
clearInterval(intervalFun);
if (isDataChanged) {
clrIntervalFun1 = setTimeout(() => { intervalFun = setInterval(() => this.startTimer(), 1000); }, 0);
} else {
intervalFun = setInterval(() => this.startTimer(), 1000);
}
}
startTimer(): void {
let oldValue: number;
const newValue: any = 0;
for (let i: any = 0; i < this.grid.currentViewData.length; i++) {
if (this.grid.currentViewData[i] === undefined) {
return;
}
if (i % 2 === 0) {
let num: number = Math.floor(Math.random() * 99) + 1;
num *= Math.floor(Math.random() * 2) === 1 ? 1 : -1;
num = num * 0.25;
isDataBound = true;
oldValue = this.grid.currentViewData[i]['Net'];
this.grid.setCellValue(this.grid.currentViewData[i]['CountryCode'], 'Net', parseFloat(num.toFixed(2))); //updates the new data to the row cell
}
. . .
}
}
public getTradeData(dataCount?: number): Promise<Object> {
. . .
for (let i: any = 1; i <= dataCount; i++) {
clrIntervalFun2 = setTimeout(() => {
tradeData.push({
'CountryCode': contryNames[Math.floor(Math.random() * contryNames.length)]
+ contryNames[Math.floor(Math.random() * contryNames.length)],
'change': (Math.floor(Math.random() * 201) - 90 * 0.96).toFixed(2),
'Net': (Math.floor(Math.random() * 201) - 90 * 2.95).toFixed(2),
'Rating': rating[Math.floor(Math.random() * rating.length)],
});
if (i === dataCount) {
deferred.resolve(tradeData);
}
}, 500);
}
return deferred.promise;
}
}
|
|
@Component({
selector: 'app-root',
template: `<ejs-grid #grid [dataSource]='data' [allowPaging]=’true’
height='300' (actoinComplete)='complete($event)'>
<e-columns>
. . .
</e-columns>
</ejs-grid>`
})
export class AppComponent extends Subject<DataStateChangeEventArgs> implements OnInit {
public data: Object[] = [];
@ViewChild('grid')
public grid: GridComponent;
complete (args: any): void {
if (e.requestType === 'paging') {
console.log(this.grid.getRows()); // gets the Current View row elements
console.log(this.grid.getRowsObject());// gets the Current View row objects
}
}
|
|
@Component({
selector: 'fetchdata',
template: ` <button ej-button class='e-flat' (click)='click()'>Change Model</button>
<ejs-grid #grid [dataSource]='data' allowPaging="true" height="320" (actionComplete)='complete($event)'>
<e-columns>
<e-column *ngFor="let hitem of items" field='{{hitem.DisplayBinding}}' headerText='{{hitem.HeaderText}}'></e-column>>
</e-columns>
</ejs-grid>`
})
export class FetchDataComponent {
. . .
ngOnInit(): void {
this.data = new DataManager({
url: 'api/Orders',
adaptor: new WebApiAdaptor
});
}
click(): void {
const data:any = { OrderID: this.ID++, CustomerID: "Modified", EmployeeID: 10 };
const keyField = this.grid.getPrimaryKeyFieldNames()[0];
const ajax = new Ajax();
ajax.type = "PUT";
ajax.url = "api/Orders";
ajax.data = JSON.stringify({
value: data,
action: 'update',
keyColumn: keyField,
key: data[keyField]
})
ajax.send(); // sending AJAX to change model
this.grid.refresh();
};
}
|
|
@Component({
selector: 'fetchdata',
template: `<ejs-grid #grid [dataSource]='data' allowPaging="true" height="320" (actionComplete)='complete($event)'>
<e-columns>
<e-column *ngFor="let hitem of items" field='{{hitem.DisplayBinding}}' headerText='{{hitem.HeaderText}}'></e-column>>
</e-columns>
</ejs-grid>`
})
export class FetchDataComponent {
. . .
@ViewChild('grid')
public grid: GridComponent;
ngOnInit(): void {
this.data = new DataManager({
url: 'api/Orders',
adaptor: new WebApiAdaptor
});
}
complete(args: any): void {
if (args.requestType === 'paging') {
console.log(this.grid.currentViewData); // gets the Current View Data
console.log(this.grid.getCurrentViewRecords()); // gets the Current View Data
}
}
}
|
|
export class FetchDataComponent {
. . .
updateModel(e:any) {
const data: any = e;
const ajax = new Ajax();
ajax.url = "Home/Update";
ajax.data = JSON.stringify(data);
ajax.send(); // AJAX request to make change in Data model
ajax.onSuccess = function (gridData: any) {
grid.dataSource = new DataManager({
json: JSON.parse(gridData),
adaptor: new RemoteSaveAdaptor
});
}
}
click(): void {
. . .
this.updateModel(data);
};
}
|
|
@Component({
selector: 'fetchdata',
template: '<button ej-button class='e-flat' (click)='click()'>Change Model</button>
<ejs-grid #grid [dataSource]='data' (created)='created($event)' (actionFailure)='fail($event)' allowPaging="true" [editSettings]='editSettings' height="320" (actionComplete)='complete($event)'>
<e-columns>
<e-column *ngFor="let hitem of items" field='{{hitem.DisplayBinding}}' headerText='{{hitem.HeaderText}}'></e-column>>
</e-columns>
<ng-template #rowTemplate let-data>
<tr class="e-row">
. . .
<td class="e-rowcell"><input value="{{data.EmployeeID}}" /> <button ejs-button (click)="update($event)" cssClass="e-success">Update</button></td>
</tr>
</ng-template>
</ejs-grid>'
})
export class FetchDataComponent {
. . .
update(e: any): void {
. . .
this.updateModel(Object.assign(data, {EmployeeID:val}));
}
updateModel(e:any) {
. . .
ajax.onSuccess = function (gridData: any) {
const grid = (document.getElementsByClassName('e-grid')[0] as any).ej2_instances[0];
grid.dataSource = new DataManager({
json: JSON.parse(gridData),
adaptor: new RemoteSaveAdaptor
});
}
}
|
|
onClickMe():void{
this.data[0]['CustomerID'] = "SUPRD";
this.data = [...this.data]
}
|
Query: In push technique we have to notify when object model is changed but we need a approach where we update model in update the Grid UI same time.We have already logged “Need to provide pipeline support” as a feature and this support will be available in any of our upcoming release.Regards,Pavithra S.