如何在PrimeNG表格的新表单控件上启动行编辑模式?

huangapple go评论60阅读模式
英文:

How can I start row edit mode on a new form control in a primeng table?

问题

我有一个从表单数组中获取数据的PrimeNG表格。

我想在该表单数组的新表单控件上以编程方式启动行编辑模式。

我一直在尝试使用这个函数,但我不知道如何正确使用它:

table.initRowEdit();

public addNewElement(): void {
    const newFormGroup = new FormGroup({
      code: new FormControl(null),
      type: new FormControl(null),
    });
    this.formArray.insert(0, newFormGroup);
    this.table.initRowEdit(this.formArray.controls[0]);
}

如果我在模板中点击带有注释的按钮:pInitEditableRow,它会按预期工作。但是我想添加一行新数据并在不必点击任何按钮的情况下开始编辑。

英文:

I have a primeng table that takes data from a form array.

I want to start row edit mode on a new form control of that form array programmatically.

I've been trying using this function but I do not know how to use it properly:

table.initRowEdit();

public addNewElement(): void {
    const newFormGroup = new FormGroup({
      code: new FormControl(null),
      type: new FormControl(null),
    });
    this.formArray.insert(0, newFormGroup);
    this.table.initRowEdit(this.formArray.controls[0]);
  }

If I click in the template button annotated with: pInitEditableRow it works as expected. But I want to add a new row and start editing it without having to click in any button.

答案1

得分: 1

好的,

我找到了解决方案...

public addNewElement(): void {
  const newFormGroup = new FormGroup({
    code: new FormControl(null),
    type: new FormControl(null),
  });
  this.formArray.insert(0, newFormGroup);
  this.table.initRowEdit(this.formArray.controls[0].value);
}
英文:

Ok,

I've found the solution...

public addNewElement(): void {
const newFormGroup = new FormGroup({
  code: new FormControl(null),
  type: new FormControl(null),
});
this.formArray.insert(0, newFormGroup);
this.table.initRowEdit(this.formArray.controls[0].value);

}

huangapple
  • 本文由 发表于 2023年3月9日 18:19:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75683236.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定