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

Using ng2-smart-table, can I change the value of a cell in a row after being added?

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

我有一个智能 table (mode=inline),有 3 列:id、column1 和 column2。 Id 不是 editable 因为在我调用后端并生成行之前,我不知道该值,因此当我添加新行时,ID 的单元格保持为空。

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

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

有人遇到过同样的问题吗?这个流程是完全可能的还是组件的限制?

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

任何帮助将不胜感激。

终于,在花了很多时间之后得到了这个...希望能帮到你!!!

在这里,当您最初单击 Add New 时,您会看到空单元格,其中 id 将被禁用,您会将值插入到 column1列 2单击 create 按钮 时,您的 post 调用发生在 onPostCall 方法中,并且等待 响应 然后更新单元格值并且 最终根据您的要求显示值 当您点击 编辑 按钮

时也会发生同样的情况

yourapp.component.html

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

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);
                 }

 //in your settings
 settings = {
     add: {
           confirmCreate: true,
          },
    edit: {
           confirmSave: true,
          },
// 
  columns: {
            // other columns
            id: {
                editable: false,
                addable: false,
               }
           },
}

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});
}

不要忘记在 app.module.ts 的提供商中添加条目 YourService !!