使用ng2-smart-table,我可以在添加后更改连续单元格的值吗?

Jav*_*eva 3 ng2-smart-table angular

我在我的项目中使用ng2-smart-table组件,我发现了一个阻碍我的问题.

我有一个智能表(mode = inline),有3列:id,column1和column2.Id不可编辑,因为在我调用后端并生成行之前,我不会知道值,因此当我添加新行时,ID的单元格仍为空.

我正在听发射器"onCreateConfirm",当它被触发时,我用后置请求调用我的后端并等待响应.

当我处理响应时,我一直无法找到更新行中该单元格的方法.

有人遇到同样的问题吗?这种流程是否可行,或者是组件的限制?

也许我做错了什么,我根本不应该遵循这个流程,还有另一种方法可以做到这一点.

任何帮助将不胜感激.

Amp*_*esh 8

最后,花了很多时间得到这个...希望这个帮助!

在这里,当您最初单击Add New时,您将获得将禁用id的空单元格,并将值插入column1,column2.在单击" 创建"按钮时,在onPostCall方法中调用您的帖子并等待响应然后更新单元格值,最后根据您的要求显示该值, 当您单击" 编辑"按钮时也会发生相同的情况

yourapp.component.html

<ng2-smart-table [settings]="settings"  [source]="data"
(createConfirm)="onPostCall($event)" 
(editConfirm)="onPostCall($event)">
</ng2-smart-table>
Run Code Online (Sandbox Code Playgroud)

yourapp.component.ts

 async onPostCall(event){
       this.value= await this.yourService.
                        getId(yourarg).first().toPromise();

                  event.newData.id =this.value
                   //  console.log(this.value);

                  event.confirm.resolve(event.newData);
                 }
Run Code Online (Sandbox Code Playgroud)
 //in your settings
 settings = {
     add: {
           confirmCreate: true,
          },
    edit: {
           confirmSave: true,
          },
// 
  columns: {
            // other columns
            id: {
                editable: false,
                addable: false,
               }
           },
}
Run Code Online (Sandbox Code Playgroud)

your.service.ts

 getId(value:any){
  // your options here e.g,let options = new RequestOptions({  method: RequestMethod.Post });
  // your content here e.g, let body = JSON.stringify(value);
  return this.http.post('your_url',
          body,
          options
          ).map(res => {return res.json().yourvalue});
}
Run Code Online (Sandbox Code Playgroud)

别忘了在app.module.ts的提供者中添加条目YourService !!