如何在Infragistics网格中将一个Igx-column的值传入另一列
解决Infragistics网格中跨列获取当前行字段值的问题
嘿,我懂你现在卡在哪了——你想用模板变量#docid拿第一列的documentId值,结果输出[object Object],对吧?这是因为#docid引用的是IgxColumnComponent的实例对象,不是当前行的具体字段值,直接插值自然会显示对象的字符串形式啦。
下面给你两种简单好用的解决方法:
方法一:直接从当前行数据中取值
最直观的方式是通过cell.context.row.data访问当前行的完整数据,直接提取documentId字段:
<igx-column field="documentId" header="Document Id" [filterable]="true" dataType="string" style="font-size:20px"> </igx-column> <igx-column field="source" header="Source" [filterable]="true" dataType="string" style="font-size:10px"> <ng-template igxCell let-cell="cell"> <div *ngIf="cell.value==2"> <span> {{ cell.context.row.data.documentId }} <img src="../../assets/icons/po-ack-Icon.png" /> </span> </div> </ng-template> </igx-column>
cell.context.row.data里包含了当前行的所有原始数据,直接通过字段名就能拿到对应值,这种方式适合字段名固定的场景。
方法二:通过行实例+列引用动态取值
如果你的列配置是动态的(比如field可能变化),可以借助行实例的getCellValue方法,结合列的引用获取值:
<igx-column #docid field="documentId" header="Document Id" [filterable]="true" dataType="string" style="font-size:20px"> </igx-column> <igx-column field="source" header="Source" [filterable]="true" dataType="string" style="font-size:10px"> <ng-template igxCell let-cell="cell" let-row="row"> <div *ngIf="cell.value==2"> <span> {{ row.getCellValue(docid.field) }} <img src="../../assets/icons/po-ack-Icon.png" /> </span> </div> </ng-template> </igx-column>
这里我们用let-row="row"拿到当前行实例,调用row.getCellValue()方法并传入docid列的field属性,就能动态获取对应列的当前行值,灵活性更高。
这两种方法都能帮你正确拿到第一列的documentId值,替换掉之前显示[object Object]的问题~
内容的提问来源于stack exchange,提问作者Tihomir Tonev
相关产品推荐
相关产品推荐

