- Typescript
- ABP + .NET Core
Currently utilizing a grid for row insertion, specifically a component of the DevExtreme framework. Similar to other grids, it triggers onRowInserting
events when records are inserted with the inserted row as a parameter. I'm in need of converting this "anonymous" object (inserted data) into my client-side DTO within this event.
onRowInserting(e) {
let mynewrow: ItemDto = e.data; // e.data holds the inserted row
}
To gain a clearer understanding of my goal, refer to the following post:
Add rows to DevExtreme grid (angular) - model/schema
EDIT
The structure of ItemDto
:
export class ItemDto implements IItemDto {
description: string;
note: string;
quantity: number;
postId: number;
id: number;
constructor(data?: IItemDto) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
}
}
init(data?: any) {
if (data) {
this.description = data["description"];
this.note = data["note"];
this.quantity = data["quantity"];
this.postId = data["postId"];
this.id = data["id"];
}
}
static fromJS(data: any): ItemDto {
let result = new ItemDto();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["description"] = this.description;
data["note"] = this.note;
data["quantity"] = this.quantity;
data["postId"] = this.postId;
data["id"] = this.id;
return data;
}
clone() {
const json = this.toJSON();
let result = new ItemDto();
result.init(json);
return result;
}
}
export interface IItemDto {
description: string;
note: string;
quantity: number;
postId: number;
id: number;
}
Below is the content of e.data
(some columns not included since only a few fields have been added to the grid at this point).
Object {
__KEY__: "7c2ab8-1ff6-6b53-b9d7-ba25c27"
description: "mydescription"
id: 32
note: "mynote"
postId: 4
quantity: 2
> __proto__: Object { constructor; , _defineG....
}
For a visual representation of the object, refer to this image: https://i.sstatic.net/XkEB1.jpg
Uncertain about the line let mynewrow: ItemDto
. Unsure if it's correct or sufficient for later use, such as passing it to the service responsible for saving the new row.