DataTable Edit无法使用二维验证 [英] DataTable Edit Can not validate with two-dimensional

查看:60
本文介绍了DataTable Edit无法使用二维验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到有关数据表编辑器的问题

I face an issue about Datatable Editor

我的表是PrimeNG的数据表,该表可以编辑该行的任何单元格,并且所有单元格都是必需的:

My table is data table of PrimeNG, this table can edit any cell of the row and all cell is required:

这是数据表的要求:

可以编辑任何单元格
验证任何单元格(必填) b $ b当我完成2个要求时,输入为空白时,输入会引发一个错误

can edit any cell validate any cell (required) when I finished 2 requirements, the input raise up a bug when the input is blank

Error: If ngModel is used within a form tag, either the name attribute must be set or the form
  control must be defined as 'standalone' in ngModelOptions.

  Example 1: <input [(ngModel)]="person.firstName" name="first">

我认为问题是名称为空,并且输入值相同时重复。

i think the problem is the name is blank and duplicate when input have same value.

现在我要设置每个输入的属性名称

now I want to set the attribute name of each of input like this

[name]="`{col.field}` + '_' + `value of first row` + '_' + data[col.field]"

这将使输入是唯一的,我该怎么做或有人建议我另一种解决方案

this will make the input is unique, how i can do that or some one suggest me an other solution

这是Plunker
https://plnkr.co/edit/n0S4JK1siLvDHypTSpkZ?p=preview

and here is Plunker https://plnkr.co/edit/n0S4JK1siLvDHypTSpkZ?p=preview

推荐答案


我认为问题是名称为空,输入时重复相同的值。

i think the problem is the name is blank and duplicate when input have same value.

确实,您是对的。您遇到的错误意味着您必须具有 name 属性,并且该属性永远不能为空。但是,当您删除单元格值时, data [col.field] 变为空,因此 name 属性。

Indeed, you are right. The error you have means that you must have a name property and this one should never be empty. But when you remove your cell value, data[col.field] becomes empty and so the name property.

因此,要解决您的问题,请勿依赖此值。因此,您可以做的是分配行索引和列索引的串联。类似于 rowIndex_columnIndex

So to solve your problem, you should not depend on this value. What you can do therefore is to assign the concatenation of the index of the row and the index of the column. Something like rowIndex_columnIndex :

<form (ngSubmit)="onSubmit()" #form="ngForm">
<p-dataTable [value]="data" [editable]="true">
  <p-column *ngFor="let col of cols,let j=index" [field]="col.field" [editable]="true" [header]="col.header">
    <ng-template let-col let-data="rowData" pTemplate="editor" let-i="rowIndex">
      <input [(ngModel)]="data[col.field]" pInputText required="true" [name]="i+'_'+j"/>
    </ng-template>
  </p-column>
</p-dataTable> 

其中,i是行的索引,j是列的索引。

where i is the index of the row and j the index of the column.

查看正在使用的柱塞

这篇关于DataTable Edit无法使用二维验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆