【问题标题】:Access row datasource object in Grid column template访问 Grid 列模板中的行数据源对象
【发布时间】:2019-12-11 11:02:52
【问题描述】:

我正在使用来自 Syncfusion Angular UI Components (Essential JS 2) 的 Grid 组件 (ejs-grid)。

一个问题是,当使用列模板时,我无法从数据源访问当前行的原始对象。这就是为什么点击Stackblitz中某个单元格中的黑色方块后,网格下的输出是:

是否一样:假

let-data 变量不保存数据源中的原始对象,而是保存它的一些副本。

HTML 模板:

<ejs-grid [dataSource]='data' rowHeight='38' height='200' width="300">
    <e-columns>
        <e-column field='name' headerText='Employee Name' width='200'>
            <ng-template #template let-data>
                <div>
                    <span>{{ data.name }}</span>
                    <span>{{ data.testFunc() }}</span>
                    <span
                        (click)="onClick(data)"
                        class="clickable">
                    </span>
                </div>
            </ng-template>
        </e-column>
    </e-columns>
</ejs-grid>
<div>Is the same: {{ isTheSame !== undefined ? isTheSame : 'undefined' }}</div>

TypeScript 组件代码:

export class Item {
    public constructor(public readonly name: string) {
    }

    public testFunc(): string {
        return "testFunc " + this.name;
    }
}

@Component({
    selector: 'app-root',
    templateUrl: 'app.component.html',
    styleUrls: ['app.component.css'],
    providers: [FilterService,VirtualScrollService]
})
export class AppComponent {
    public data: ReadonlyArray<any> = [new Item("Name1")];

    public isTheSame: boolean | undefined;

    public onClick(dataItem: any): void {
        this.isTheSame = dataItem === this.data[0];
    }
}
  1. 除了let-data,还有其他变量可以绑定列模板来获取原始行数据吗?如果没有,有什么解决方法?

  2. 谁能指出我的 docs\Gitub 源代码,其中包含列模板可用的所有变量的列表?除了let-datalet-clientData,我至少还知道一个。

【问题讨论】:

    标签: angular typescript syncfusion


    【解决方案1】:

    默认情况下,列模板渲染提供额外的详细信息(如列对象、索引等)以及行数据。此明细用于根据用户场景自定义模板列。因此,在将此对象与data[0] 进行比较时,它总是失败。

    【讨论】:

    • 谢谢。我知道为什么data[0] 的比较失败了。这是这里的确切问题。但是,问题是如何从数据源访问 original 项目,而不是从 Grid 内部克隆并通过 let-data 提供的数据源项目访问某种对象?
    • 另外,如果您正在使用 Syncfusion,请在您的回答中注明。我猜它是 StackOverflow \ StackExchange 政策规则。
    猜你喜欢
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 2013-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多