【问题标题】:Any examples for angular2 ag-grid pagination?angular2 ag-grid 分页的任何示例?
【发布时间】:2016-11-02 19:55:40
【问题描述】:

angular2 ag-grid 分页的任何示例,尤其是在虚拟分页/无限滚动上?我已经搜索了一段时间,没有发现任何有用的东西。非常感谢任何帮助!

这是我的html:

 <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>

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

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);
            }
        }
    }

【问题讨论】:

  • 请在此处描述您的具体问题。

标签: angular pagination ag-grid


【解决方案1】:

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

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

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

        <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)

【讨论】:

  • 我已经把我的代码贴在下面了,你能帮我看看吗?我不知道怎么了..
  • 文档没有类型脚本示例,我遇到了 ag-grid 中的分页问题
猜你喜欢
  • 1970-01-01
  • 2018-05-09
  • 2018-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-28
  • 2018-10-10
  • 2021-01-22
相关资源
最近更新 更多