如何使用模态对话框Angular 2编辑ngxdatatable(How to edit ngxdatatable using modal dialog Angular 2)
- 我想做的事
我的ngxdatatable中有一个办公室名称和部门列表。 每一个officename,我都有编辑和删除按钮 ,用户可以编辑和删除officename / dept。
编辑部分,我想要在用户单击编辑功能时弹出模态对话框 ,并显示officename和dept细节 。 用户可以编辑officename和/ dept保存。
- 我取得了什么
我设法在用户点击编辑功能时弹出模态对话框
不知何故,我将原始值传递给编辑模式对话框时遇到问题
- 我的问题
我想将原始值传递给模态对话框(处理它)
并允许用户编辑officename / dept并保存编辑的细节我的代码,这是我的模态对话框
<div bsModal #editOffice="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true"> <div class="modal-dialog modal-md"> <div class="modal-content"> <form [formGroup]="EditOfficeForm" (ngSubmit)="EditOfficeForm.valid && updateOffice(EditOfficeForm.value)" novalidate> <div class="modal-header"> <button type="button" class="close" (click)="editOffice.hide()" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title">Edit Office</h4> </div> <div class="modal-body"> <div class="form-group row"> <label class="col-md-3 form-control-label" for="text"> Office Name</label> <div class="col-md-4"> <input #officeName type="text" id="officeName" name="officeName" class="form-control" formControlName="officeName" value="{{editingData.officeName}}"> <div class='redColor' *ngIf="EditOfficeForm.controls.officeName.touched"> <div *ngIf="EditOfficeForm.controls.officeName.hasError('required')">Required.</div> </div> </div> </div> <div class="form-group row"> <label class="col-md-3 form-control-label" for="text"> Date </label> <div class="col-md-4"> <input #dept type="text" id="dept" name="dept" class="form-control ng-pristine ng-valid ng-touched" formControlName="dept" value="{{editingData?.dept}}"> <div class='redColor' *ngIf="EditHolidayForm.controls.dept.touched"> <div *ngIf="EditHolidayForm.controls.dept.hasError('required')">Required</div> </div> </div> </div> <button type="button" class="btn btn-space pull-right" (click)="editOffice.hide()" aria-label="Close"> Cancel </button> <button class='btn btn-primary' type='submit' (click)="editOffice.hide()" [disabled]='!EditOfficeForm.valid'>Submit</button> <br> </div> </form> </div> </div> </div>
我的组件文件
export class OfficeComponent { @Output() public rowEdited: EventEmitter<any> = new EventEmitter(); public editingData:EditingRowData; EditOfficeForm: FormGroup; officename: FormControl; dept:FormControl; constructor(private fb: FormBuilder, public http: Http, private dataService: DataService) { this.EditOfficeForm= fb.group({ officename: this.officename, dept:this.dept }) } ngOnInit() { this.getAllOffice(); } getAllOffice() { /// getting all officefrom service } editOffices(rowDetails:any): void { this.rowEdited.emit({rowDetails}); console.log('row details', { rowDetails }); //SEND THIS VALUE TO POPUP DIALOG this.editingData = rowDetails // this.editingData contain ALL THE SELECTED OFFICENAME AND DEPT DETAILS. SO I WANT TO DISPLAY THIS DATA IN MY MODAL DIALOG HTML. } updateOffice(value: Object): void { //updating and passed to database } }
我一直都没有定义主题 。 我尝试做这个
editingData?officename
,它开始显示在我的模态对话框中。 但是,假设用户只编辑主管名称并将部门保留为原始数据,则其捕获的值为{officename:"newOfficename", dept:null}
所以我想要正确编辑和保存细节。
如果用户只编辑一个(officename / dept),那么其他数据仍应保留
原始数据并保存
What I want to do
I have a list of office names and dept in my ngxdatatable. Each officename has an edit and delete button, which a user can use to edit and delete the officename/dept.
For the edit part, I want a modal dialog to pop whenever the edit button is clicked (linked to an edit function), and show the officename and dept details. and User can edit the officename and/dept save it.
What I have achieved
I managed to have the modal dialog pop when a user clicks the edit button. Somehow, I have a problem when passing the original value to the edit modal dialog.
My problem
I want to pass my original value to modal dialog (working on it) and allow the user to edit the officename/dept and save the edited detail.
My Code, this is my modal dialog
<div bsModal #editOffice="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true"> <div class="modal-dialog modal-md"> <div class="modal-content"> <form [formGroup]="EditOfficeForm" (ngSubmit)="EditOfficeForm.valid && updateOffice(EditOfficeForm.value)" novalidate> <div class="modal-header"> <button type="button" class="close" (click)="editOffice.hide()" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title">Edit Office</h4> </div> <div class="modal-body"> <div class="form-group row"> <label class="col-md-3 form-control-label" for="text"> Office Name</label> <div class="col-md-4"> <input #officeName type="text" id="officeName" name="officeName" class="form-control" formControlName="officeName" value="{{editingData.officeName}}"> <div class='redColor' *ngIf="EditOfficeForm.controls.officeName.touched"> <div *ngIf="EditOfficeForm.controls.officeName.hasError('required')"> Required. </div> </div> </div> </div> <div class="form-group row"> <label class="col-md-3 form-control-label" for="text"> Date </label> <div class="col-md-4"> <input #dept type="text" id="dept" name="dept" class="form-control ng-pristine ng-valid ng-touched" formControlName="dept" value="{{editingData?.dept}}"> <div class='redColor' *ngIf="EditHolidayForm.controls.dept.touched"> <div *ngIf="EditHolidayForm.controls.dept.hasError('required')"> Required </div> </div> </div> </div> <button type="button" class="btn btn-space pull-right" (click)="editOffice.hide()" aria-label="Close"> Cancel </button> <button class='btn btn-primary' type='submit' (click)="editOffice.hide()" [disabled]='!EditOfficeForm.valid'>Submit</button> <br> </div> </form> </div> </div> </div>
my component file
export class OfficeComponent { @Output() public rowEdited: EventEmitter<any> = new EventEmitter(); public editingData:EditingRowData; EditOfficeForm: FormGroup; officename: FormControl; dept:FormControl; constructor(private fb: FormBuilder, public http: Http, private dataService: DataService) { this.EditOfficeForm= fb.group({ officename: this.officename, dept:this.dept }) } ngOnInit() { this.getAllOffice(); } getAllOffice() { /// getting all officefrom service } editOffices(rowDetails:any): void { this.rowEdited.emit({rowDetails}); console.log('row details', { rowDetails }); //SEND THIS VALUE TO POPUP DIALOG this.editingData = rowDetails // this.editingData contain ALL THE SELECTED OFFICENAME AND DEPT DETAILS. // SO I WANT TO DISPLAY THIS DATA IN MY MODAL DIALOG HTML. } updateOffice(value: Object): void { //updating and passed to database } }
I keep getting officename undefined and I tried using
editingData?officename
and it started to display in my modal dialog. But, let's say the user only edits the officename and leaves the dept as the original data, then the value it captured is{officename:"newOfficename", dept:null}
.So I want the details to be properly edited and saved.
If the user edit only one (officename/dept) only that one should be changed while the remaining data remains untouched.
原文:https://stackoverflow.com/questions/43427113
最满意答案
尝试这个
DELETE FROM BLOGS WHERE `id` NOT IN (SELECT id FROM `USER`);
try this
DELETE FROM BLOGS WHERE `id` NOT IN (SELECT id FROM `USER`);
相关问答
更多-
有什么数据库专业书籍介绍?[2022-05-19]
mysql -
Mysql - 从一个查询的多个表中删除[duplicate](Mysql - delete from multiple tables with one query [duplicate])[2022-03-04]
您可以使用ON DELETE CASCADE选项在表上定义外键限制。 然后从父表中删除记录将从子表中删除记录。 检查此链接: http : //dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html You can define foreign key constraints on the tables with ON DELETE CASCADE option. Then deleting the record from pa ... -
你不能用分号分隔它们吗? Delete from messages where messageid = '1'; Delete from usersmessages where messageid = '1' 要么 只需使用INNER JOIN如下 DELETE messages , usersmessages FROM messages INNER JOIN usersmessages WHERE messages.messageid= usersmessages.messageid and m ...
-
在MySQL中查询2个表(Query in MySQL between 2 tables)[2022-07-20]
我认为查询很好,但我会使用反连接。 SELECT cp.ProductID, ProductTitle FROM cms_products cp LEFT JOIN cms_group_products cgp ON (cp.ProductID = cgp.ProductID AND gID = 1000) WHERE cgp.ProductID IS NULL I think the query is fine, but I would use an anti-join. SELECT cp.Produ ... -
DELETE Content, Votes FROM Content LEFT JOIN Votes ON Votes.ContentID = Content.ContentID WHERE Content.ContentID = ? DELETE Content, Votes FROM Content LEFT JOIN Votes ON Votes.ContentID = Content.ContentID WHERE Content.ContentID = ?
-
通过Logstash在Elasticsearch中导入MySQL-Entrys(Import MySQL-Entrys in Elasticsearch over Logstash)[2022-05-07]
为了将数据从MySQL数据导入弹性搜索索引,您应该使用jdbc插件,如上面建议的@hurb。 您的logstash jdbc输入可能如下所示: input { jdbc { jdbc_connection_string => "jdbc:mysql://yourhost:3306/yourdb" jdbc_user => "root" jdbc_password => "root" jdbc_validate_connection = ... -
尝试这个 DELETE FROM BLOGS WHERE `id` NOT IN (SELECT id FROM `USER`); try this DELETE FROM BLOGS WHERE `id` NOT IN (SELECT id FROM `USER`);
-
一个mysql查询中的3个表?(3 tables in one mysql query?)[2022-04-05]
我假设你的查询的friends_db部分实际上是friends表?我也假设这些表之间有关系: 如果是这样,您可以使用联接: select * from friends as f join users as u on u.user_id = f.user_id join posts as p on p.user_id = f.user_id where f.user_id = ... 或者,为了让你的朋友'发帖: select * from posts as p join users as u on u. ... -
MySQL从3个表中删除(MySQL delete from 3 tables)[2023-09-14]
MySQL支持多表删除 : DELETE FROM BOOKINGS USING BOOKINGS JOIN SESSIONS JOIN COURSES WHERE BOOKINGS.session_id = SESSIONS.session_id AND SESSIONS.course_id = COURSES.course_id AND COURSES.course_id = ? 另一种方法是使用存储过程 ,并按正确的顺序处理删除: BOOKINGS DELETE FROM BOOK ... -
从多个Mysql表中删除(Delete from multiple Mysql tables)[2021-12-27]
使用显式Join语法 delete s,i from services s left join images i on i.service_id = s.id where s.id = 3 Use explicit Join syntax delete s,i from services s left join images i on i.service_id = s.id where s.id = 3