首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有angular2 ag-grid分页的例子?

有没有angular2 ag-grid分页的例子?
EN

Stack Overflow用户
提问于 2016-06-30 23:46:25
回答 1查看 5.4K关注 0票数 0

有没有angular2 ag分页的例子,特别是虚拟分页/无限滚动?我已经搜索了一段时间,但没有找到任何有用的东西。任何帮助都是非常感谢的!

这是我的html:

代码语言:javascript
复制
 <ag-grid-ng2 #agGrid  class="ag-fresh" style="height: 300px"
      [gridOptions]="gridOptions" 
      [rowGroupPanelShow]="always" 
      [columnDefs]="columnDefs" 
      [datasource] = "dataSource"
      rowModelType = "virtual"
      enableFilter 
      enableSorting 
      enableColResize
      (modelUpdated)="onModelUpdated()"
      >
    </ag-grid-ng2>

这是我在控制器中的数据源方法:

代码语言:javascript
复制
private createDataSource() {
        if (!this.rowData) {
            //in case user selected 'onPageSizeChanged()' before the json was loaded
            return;
        }
        console.log("this.rowData " + this.rowData.length);
        console.log("Obtaining datasource");
        this.dataSource = {
            rowCount: null, // behave as infinite scroll
            pageSize: 2,
            overflowSize:1,       
            getRows: function (params) {
                console.log('asking for ' + params.startRow + ' to ' + params.endRow);
                // At this point in your code, you would call the server, using $http if in AngularJS.
                // To make the demo look real, wait for 500ms before returning
                setTimeout(function () {
                    // take a slice of the total rows
                    var rowsThisPage = this.rowData.slice(params.startRow, params.endRow);
                    // if on or after the last page, work out the last row.
                    var lastRow = -1;
                    if (this.rowData.length <= params.endRow) {
                        lastRow = this.rowData.length;
                    }
                    // call the success callback
                    params.successCallback(rowsThisPage, lastRow);
                }, 500);
            }
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2016-07-01 00:43:35

看看ng2 example on github,以及Virtual Paging上的ag-Grid文档

如果您在ng2示例中查看app.component.html,您将看到在那里设置了许多(例如,enableColResize)。

只需按照ag-Grid文档以相同的方式添加rowModelType和数据源-例如:

代码语言:javascript
复制
        <ag-grid-ng2 #agGrid style="width: 100%; height: 350px;" class="ag-fresh"

                 [gridOptions]="gridOptions"
                 [columnDefs]="columnDefs"
                 [showToolPanel]="showToolPanel"
                 [rowData]="rowData"

                 [rowModelType] = "virtual"
                 [datasource] = "myDataSource"

                 enableColResize
                 ...other properties...

在相应的组件中定义了myDataSource (示例中的AppComponent)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38127869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档