I am getting data from api like below.
1. Address: "NETRA
NIRAMAY NIKETAN VIVEK NAGAR CHAITANYAPUR,(HALDIA) DIST.PURBA,MEDINIPUR INDIA
721645,IN"
2.
Balance: "8,198.24"
3. BillingCurrency: "INR"
4.
BusinessAlias: "4021667"
5. CCNumber: "CHI6"
6. CaseId: "Check
LaSCA"
7. City: "MEDINIPUR"
8. CollectorName: "SINGH,
ASHISH KUMAR"
9. CustomerNo: "0001569763"
10. Definer: ""
11. ExtendedName: "Vivekananda
Mission Ashram"
12. IsSensitiveCustomer: ""
13. Name: "VIVEKANANDA
MISSION ASHRAM"
14. NativeAddress: "Netra
Niramay Niketan VIVEK NAGAR,CHAITANYAPUR,,,,,,,,"
15. OpenItems: "1"
16. OrgId: ""
17. PLName: "HEALTHCARE
INDIA - CALCUTTA"
18. ParentSub: "
"
19. PhoneNo: "918049308268
FX:"
20. Ssoid: "000000000"
21. Status1: "Active"
1. Address: "ELAYAMPALAYAM
(PO),TIRUCHENGODE (TK),NAMAKKAL INDIA 637205,IN"
2.
Balance: "-108,311.06"
3. BillingCurrency: "INR"
4.
BusinessAlias: "2439217"
5. CCNumber: "CHI8"
6. CaseId: "Check
LaSCA"
7. City: "NAMAKKAL"
8. CollectorName: "M
SHETTY, LOKESH"
9. CustomerNo: "0001505640"
10. Definer: ""
11. ExtendedName: "VIVEKANANDHA
MEDICAL CARE HOSPITAL"
12. IsSensitiveCustomer: ""
13. Name: "VIVEKANANDHA
MEDICAL CARE HOSPITAL"
14. NativeAddress: "ELAYAMPALAYAM
(PO),,,,,,,,"
15. OpenItems: "3"
16. OrgId: ""
17. PLName: "HEALTHCARE
INDIA - CHENNAI"
18. ParentSub: "
"
19. PhoneNo: "918049308538
FX:"
20. Ssoid: "000000000"
21. Status1: "Active"
|
[app.component.ts]
this.data = [
{
OrderID: 10248,
CustomerID: "VINET",
EmployeeID: -1.25, // use the value in number instead of string
OrderDate: new Date(8364186e5)
},
{
OrderID: 10249,
CustomerID: "TOMSP",
EmployeeID: -108.34,
OrderDate: new Date(836505e6)
},
----
];
|
|
queryCellInfo(args) { //queryCellInfo event
if(args.column.field === "EmployeeID") {
args.data.EmployeeID = parseFloat(args.data.EmployeeID); //convert string to number
args.cell.innerText = args.cell.innerText.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); //format the value with commas and it will change in UI level
}
}
|
| order ID | ID | Date |
| 10249 | -10,844.34 | 7/5/1996 |
| 10250 | 200,000.00 | 7/8/1996 |
| 10251 | -3.00 | 7/8/1996 |
|
queryCellInfo(args) {
if (args.column.field === "EmployeeID") {
args.data.EmployeeID = parseFloat(args.data.EmployeeID);
var dec = args.cell.innerText.split('.')[1] //if there is no decimal number, we have added the decimal with toFixed() method
if ( dec == undefined) {
args.cell.innerText = Number(args.cell.innerText).toFixed(2);
}
else {
args.cell.innerText = args.cell.innerText.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); //format the value with commas and it will change in UI level
}
}
} |
|
App.component.html
<div class="control-section"> <ejs-tooltip
#tooltip
target=".e-rowcell"
(beforeRender)="beforeRender($event)"
position="TopCenter"
>
<ejs-grid [dataSource]="data" (queryCellInfo)='queryCellInfo($event)' height="350" [allowSorting]="true">
<e-columns>
<e-column field="EmployeeID" headerText="ID" width="150">
<ng-template #template let-data>
<a rel='nofollow' href="https://www.w3schools.com">{{customHelper(data)}}</a>
</ng-template>
</e-column>
</e-columns>
</ejs-grid>
</ejs-tooltip>
</div>
-----------------------------------------------
App.component.ts
export class AppComponent {
public data: Object[] = [];
@ViewChild("tooltip", null)
public tooltip: TooltipComponent;
customHelper(args) {
if(typeof(args.EmployeeID) == "string") {
return args.EmployeeID.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
}
else {
var format = args.EmployeeID.toFixed(2);
return format.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
}
}
beforeRender(args) {
this.tooltip.content = args.target.closest("td").innerText;
}
queryCellInfo(args) {
if (args.column.field === "EmployeeID" && typeof(args.data.EmployeeID) == "string") {
args.data.EmployeeID = parseFloat(args.data.EmployeeID);
}
}
ngOnInit(): void {
this.data = [
];
}
}
|