Need help with updating the devextreme-datagrid. Can anyone assist?
lineController.js
router.put("/:id", (req, res) => {
if (!ObjectId.isValid(req.params.id))
return res.status(400).send(`No record with given id : ${req.params.id}`);
console.log({
msg: "Line update process",
dataReceived: req.body
});
var emp = {
// code block for updating fields
};
Line.findByIdAndUpdate(
req.params.id,
{ $set: emp },
{ new: true },
(err, doc) => {
if (!err) {
res.send(doc);
} else {
console.log(
"Error in line update:" + JSON.stringify(err, undefined, 2)
);
}
}
);
});
line.service.ts
import { Injectable } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Line} from './line.model';
@Injectable({
providedIn: 'root'
})
export class LineService {
selectedLine: Line;
lines: Line[];
readonly baseURL = 'http://localhost:3000/lines';
constructor(private http: HttpClient) { }
postLine(emp: Line) {
return this.http.post(this.baseURL, emp);
}
getLineList() {
return this.http.get(this.baseURL);
}
putLine(emp: Line) {
return this.http.put(this.baseURL + `/${emp._id}`, emp);
}
deleteLine(_id: string) {
return this.http.delete(this.baseURL + `/${_id}`);
}
}
line.component.html
<dx-data-grid
id="gridContainer"
[dataSource]="lineService.lines"
title="SQDCM Data Entry"
keyExpr="_id"
[columnAutoWidth]="true"
[showBorders]="true"
(onRowInserted)="onEdit($event)"
(onRowUpdated)="onUpdate($event)"
(onRowRemoved)="onDelete($event)"
>
line.component.ts
onUpdate(event) {
console.log(event);
const merged = {_id: event.key, ...event.data};
this.lineService.putLine(merged).subscribe(res => { });
}
When updating data, it logs to the console.
{key: "5c6ac45adb48bf3850eebc74", data: {…}, component: inheritor, element: dx-data-grıd#gridContainer.dx-widget.dx-visibility-change-handler} component: inheritor {_events: {…}, _eventsStrategy: NgEventsStrategy, callBase: undefined, _$element: initRender(1), NAME: "dxDataGrid", …} data: isKazasi: 8 proto: Object element: dx-data-grıd#gridContainer.dx-widget.dx-visibility-change-handler key: "5c6ac45adb48bf3850eebc74" proto: Object
and an error occurs:
{ msg: 'Line update process', dataReceived: { _id: '5c6ac45adb48bf3850eebc74', isKazasi: 8 } } Error in line update:{ "message": "Cast to number failed for value \"NaN\" at path \"devamsizlikYuzdesi\"", "name": "CastError", "stringValue": "\"NaN\"", "kind": "number", "value": null, "path": "devamsizlikYuzdesi" }