使用 Angular 13 在 ejs-grid 中自定义无记录模板

发布于 2025-01-10 21:19:55 字数 3592 浏览 0 评论 0原文

ejs-grid 与 Angular 一起使用并尝试自定义 No Records data 模板无法做到

<ejs-grid #assetGrid id="asset_grid" class="scrollable-body-grid"
                          (dataBound)='dataBound($event)'
                          [height]='gridBodyCalculatedHeight'
                          [dataSource]='assetList | async'
                          [enableHover]='false'
                          [searchSettings]='false'
                          allowPaging='true'
                          allowSorting="true"
                          [allowResizing]='true'
                          [pageSettings]='pageSettings'
                          (dataStateChange)='dataStateChange($event)'
                          [toolbar]="toolbar"
                          allowExcelExport='true'
                          (toolbarClick)='toolbarClickHandler($event)'
                          showColumnChooser='true'>
                    <e-columns>
                        <ng-template #template ngFor let-column [ngForOf]="gridColumns">
                            <ng-container *ngIf="column.field === 'name'">
                                <e-column [field]="column.field" [width]="column.width" [visible]="column.field !== 'id' && column.field !== 'vendorId'"
                                          [headerText]="column.headerText">
                                    <ng-template #template let-data>
                                        <a class="gridLink" title="{{data.name}}" (click)="openAsset(data)">{{data.name}}</a>
                                    </ng-template>
                                </e-column>
                            </ng-container>
                            <ng-container *ngIf="column.field !== 'name'">
                                <e-column [field]="column.field" [width]="column.width" [visible]="column.field !== 'id' && column.field !== 'vendorId'"
                                          [headerText]="column.headerText" [showInColumnChooser]="column.field !== 'id' && column.field !== 'vendorId'">
                                </e-column>
                            </ng-container>

                        </ng-template>
                    </e-columns>
                    <ng-template #EmptyRecordTemplate>
                        custom text
                      </ng-template>
                </ejs-grid>

这一点从此参考 https://www.syncfusion.com/feedback/24388/no-easy-angular-way-to-change-no-records-text,我发现emptyRecordTemplate,但它不起作用。

<ng-template #emptyRecordTemplate>
    custom text
  </ng-template>

更新

 setTimeout(function () {
            // Grid’s empty row content element is retrieved
            var emptyRowEle = this.assetGrid.element.querySelector('.e-emptyrow td');
            // The default contents are removed from the element
            emptyRowEle.innerHTML = "<p class='w-100 text-center'><span class='font-bold'>No results</span><br />Try adjusting your search by changing or removing search text.</p>";
        }.bind(this), 5)

enter图片描述在这里

能够将文本居中对齐

Using ejs-grid with angular and trying to customize the No Records data template couldn't do it

<ejs-grid #assetGrid id="asset_grid" class="scrollable-body-grid"
                          (dataBound)='dataBound($event)'
                          [height]='gridBodyCalculatedHeight'
                          [dataSource]='assetList | async'
                          [enableHover]='false'
                          [searchSettings]='false'
                          allowPaging='true'
                          allowSorting="true"
                          [allowResizing]='true'
                          [pageSettings]='pageSettings'
                          (dataStateChange)='dataStateChange($event)'
                          [toolbar]="toolbar"
                          allowExcelExport='true'
                          (toolbarClick)='toolbarClickHandler($event)'
                          showColumnChooser='true'>
                    <e-columns>
                        <ng-template #template ngFor let-column [ngForOf]="gridColumns">
                            <ng-container *ngIf="column.field === 'name'">
                                <e-column [field]="column.field" [width]="column.width" [visible]="column.field !== 'id' && column.field !== 'vendorId'"
                                          [headerText]="column.headerText">
                                    <ng-template #template let-data>
                                        <a class="gridLink" title="{{data.name}}" (click)="openAsset(data)">{{data.name}}</a>
                                    </ng-template>
                                </e-column>
                            </ng-container>
                            <ng-container *ngIf="column.field !== 'name'">
                                <e-column [field]="column.field" [width]="column.width" [visible]="column.field !== 'id' && column.field !== 'vendorId'"
                                          [headerText]="column.headerText" [showInColumnChooser]="column.field !== 'id' && column.field !== 'vendorId'">
                                </e-column>
                            </ng-container>

                        </ng-template>
                    </e-columns>
                    <ng-template #EmptyRecordTemplate>
                        custom text
                      </ng-template>
                </ejs-grid>

From this reference https://www.syncfusion.com/feedback/24388/no-easy-angular-way-to-change-no-records-text, I found emptyRecordTemplate, but it is not working.

<ng-template #emptyRecordTemplate>
    custom text
  </ng-template>

Update

 setTimeout(function () {
            // Grid’s empty row content element is retrieved
            var emptyRowEle = this.assetGrid.element.querySelector('.e-emptyrow td');
            // The default contents are removed from the element
            emptyRowEle.innerHTML = "<p class='w-100 text-center'><span class='font-bold'>No results</span><br />Try adjusting your search by changing or removing search text.</p>";
        }.bind(this), 5)

enter image description here

Able to align the text in the center

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜空下最亮的亮点 2025-01-17 21:19:55

目前,Syncfusion EJ2 Grid 不支持空记录模板。但是,我们已经将此要求的功能任务记录为“需要为空记录模板提供支持”,并将其添加到我们的功能请求数据库中。在每个发布周期的规划阶段,我们都会审查所有开放功能,并根据具体参数(包括产品愿景、技术可行性和客户兴趣)确定要实施的功能。此功能将包含在我们即将发布的任何版本中。

您可以跟踪此请求的当前状态,查看建议的解决方案时间表,并通过以下反馈链接与我们联系以获取任何进一步的疑问,

反馈链接: https://www.syncfusion.com/feedback/28548/need-to-provide-support-for-empty-record-template

所以现在我们建议您自定义 Grid 的空记录内容通过使用下面的方法,

可以通过修改Grid的create事件中的空行元素内容来实现此要求(在超时函数中,以便Grid初始化不冲突),如下面的代码片段所示,

// Grid’s created event handler 
onCreated() {
    setTimeout(function () {
        // Grid’s empty row content element is retrieved
        var emptyRowEle = this.gridObj.element.querySelector('.e-emptyrow');
        // The default contents are removed from the element
        emptyRowEle.innerHTML = "";
        // Here you can create the required content and append it to the empty row element
        var span = document.createElement('span');
        span.innerText = "Loading...";
        span.classList.add('custom-style');
        emptyRowEle.append(span);
    }.bind(this), 5)
}

请找到下面准备的示例在此供您参考,

示例: https:// /stackblitz.com/edit/angular-bqcnts?file=app.component.ts

API: https://ej2.syncfusion.com/angular/documentation/api/grid/#创建了

Currently the Syncfusion EJ2 Grid does not have support for empty record template. However, we have already logged feature task for this requirement as “Need to provide support for empty record template” and added it to our feature request database. At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. This feature will be included in any of our upcoming releases.

You can track the current status of this request, review the proposed resolution timeline, and contact us for any further inquiries through the below feedback link,

Feedback Link: https://www.syncfusion.com/feedback/28548/need-to-provide-support-for-empty-record-template

So for now we suggest you to customize the empty record content for Grid by using the below approach,

This requirement can be achieved by modifying the empty row element content in Grid’s created event(in a timeout function so that Grid initialization is not conflicted) as demonstrated in the below code snippet,

// Grid’s created event handler 
onCreated() {
    setTimeout(function () {
        // Grid’s empty row content element is retrieved
        var emptyRowEle = this.gridObj.element.querySelector('.e-emptyrow');
        // The default contents are removed from the element
        emptyRowEle.innerHTML = "";
        // Here you can create the required content and append it to the empty row element
        var span = document.createElement('span');
        span.innerText = "Loading...";
        span.classList.add('custom-style');
        emptyRowEle.append(span);
    }.bind(this), 5)
}

Please find the below sample prepared based on this for your reference,

Sample: https://stackblitz.com/edit/angular-bqcnts?file=app.component.ts

API: https://ej2.syncfusion.com/angular/documentation/api/grid/#created

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文