未捕获的TypeError:无法读取属性' setRowData'未定义的

时间:2016-04-21 18:04:51

标签: javascript angularjs ag-grid

我正在使用带有ag-grid的Angular 1.x.首先,我很困惑如何激活企业功能。我正在评估我们现在正在计划购买企业,但支持相当薄弱。

现在我试图将数据从ElasticSearch提供给网格的实际问题。我想模拟像ag-grid的演示。如果更改pagesize,它将从ES服务器检索数据,并使用新的pagesize为新网格提供数据集。为此我在任何操作上使用$ scope.gridOptions.api.setRowData(data)如果我尝试更新网格,我的意思是setRowData。我收到错误"方法未定义"它在加载页面时第一次起作用。

如何解决此问题?我错过了什么吗?

功能:这是我调用$ scope.gridOptions.api.setRowData(数据)的函数,我收到错误

"未捕获的TypeError:无法读取属性' setRowData'未定义"

  

function displayGrid(fromDate,toDate,fieldNameArray,affiliate,product,consmb,region,customer,page,pageSize)         {

   // Constructing Query from dashboard input
        var gridQuery = globalFiltersDrillDown(fromDate, toDate, fieldNameArray, page, pageSize);
        var finalGridQuery = buildQueryForDrillQuery(affiliate,product, consmb, region, customer, gridQuery, "" , false);
        console.log("final Query :" + JSON.stringify(finalGridQuery));
       var data =[];

    setTimeout(function ()
    {
       esClientIndirect.search
          (
            {
              index: esIndex1,
              type: esType1,
              size : pageSize,
              from : page,
              body: finalGridQuery
            },
            function (error, response, status)
            {
              $scope.numberOfRecords = numberCommas(response.hits.total);
              if(error)
              {
                $scope.error = "Error : " + status ;
              }
              else
              {
                var startBrace = "{ ";
                var endBrace = " }"
                data.length = 0;
                var k = 0;
                for(var o in response.hits.hits)
                {
                  var dataFields = response.hits.hits[o].fields;
                  var numberOfElements = fieldNameArray.length -1;
                  var row = startBrace;
                  for (var i in dataFields)
                  {
                    var columnName = fieldNameArray[k];
                    var columnValue =  dataFields[columnName];
                    if (k == numberOfElements)
                    {
                      row += (" \"" + columnName +"\" : \"" + columnValue +"\"");
                    }
                    else
                    {
                      row += (" \"" + columnName +"\" : \"" + columnValue +"\",");
                    }
                    k = k+1;
                  }
                  row += endBrace;
                  k =0;
                  data.push(JSON.parse(row));
                }
                // pushing data into the ag-grid
                setTimeout(function()
                {
                  $scope.gridOptions.api.setRowData(data);
                }, 200);
            }
            }, 100); // end of elastic search call back
            }); // end of elastic search set time out call back

1 个答案:

答案 0 :(得分:0)

错误表明api不存在。在进行此调用之前,您是否确定已实例化$ scope.gridOptions?