【问题标题】:ag-grid server side infinite scrolling accessing propsag-grid 服务器端无限滚动访问道具
【发布时间】:2019-08-28 22:36:26
【问题描述】:

我正在尝试按照他们的文档here 中的描述实现 ag-grid 服务器端行模型。我正在尝试做的是将 api 调用及其参数作为道具传递给网格组件。问题是,当尝试通过 this.props 或通过 this.state 访问道具时,它们都是未定义的。我的代码如下所示:

onGridReady(params) {
    this.gridApi = params.api;
    this.gridColumnApi = params.columnApi;

    this.gridApi.showLoadingOverlay();
      var dataSource = {
        rowCount: null,
        getRows: function(params) {
          setTimeout(function() {
            let serviceParams = this.props.dataServiceParams ?  this.props.dataServiceParams.slice() : {};
            serviceParams.pageSize = this.state.paginationPageSize; // this will be the rows returned per service call
            serviceParams.index =  // if there is more than 1 page for the pagesize this is the index/page to return.
            serviceParams.sortAndFilters = gridUtility.combineSortAndFilters(params.sortModel, params.filterModel);

            this.props.dataService(serviceParams)
                .then(out => {
                  var rowsThisPage = out;
                  var lastRow = -1;
                  params.successCallback(rowsThisPage, lastRow);
                });

            params.context.componentParent.gridApi.hideOverlay();
          }, 500);
        }
      };

      params.api.setDatasource(dataSource);
  };

dataService 属性包含我的服务/api 调用,而 dataServiceParams 包含服务所需的任何参数。我正在添加额外的参数来处理排序、过滤和返回所需的数据页/索引。我在这里错过了什么?

【问题讨论】:

    标签: javascript reactjs ag-grid


    【解决方案1】:

    您需要使用Arrow function 来访问父作用域的属性。检查下面的代码以获取getRowssetTimeout

      var dataSource = {
        rowCount: null,
        getRows: (params) => {
          setTimeout(() => {
            let serviceParams = this.props.dataServiceParams ?  this.props.dataServiceParams.slice() : {};
            serviceParams.pageSize = this.state.paginationPageSize; // this will be the rows returned per service call
            serviceParams.index =  // if there is more than 1 page for the pagesize this is the index/page to return.
            serviceParams.sortAndFilters = gridUtility.combineSortAndFilters(params.sortModel, params.filterModel);
    
            this.props.dataService(serviceParams)
                .then(out => {
                  var rowsThisPage = out;
                  var lastRow = -1;
                  params.successCallback(rowsThisPage, lastRow);
                });
    
            params.context.componentParent.gridApi.hideOverlay();
          }, 500);
        }
      };
    

    【讨论】:

      猜你喜欢
      • 2022-12-29
      • 2020-11-05
      • 2018-09-29
      • 2021-11-19
      • 2020-04-07
      • 2019-03-30
      • 1970-01-01
      • 2016-12-06
      • 2018-04-30
      相关资源
      最近更新 更多