我正在使用带有ag-grid的Angular1.x。首先,我很困惑如何激活企业功能。我正在评估,现在我们计划收购该企业,但是支持非常薄弱。
现在实际的问题是我试图将数据从ElasticSearch馈送到网格。我正在尝试模拟像ag-grid的演示。如果更改页面大小,它将从ES服务器检索数据,并将具有新页面大小的新数据集馈入网格。为此,如果尝试更新网格,我将在任何操作上使用$ scope.gridOptions.api.setRowData(data),我的意思是setRowData。我收到错误消息“方法未定义”,它在加载页面时首次起作用。
我该如何解决这个问题?我有什么想念的吗?
函数:这是调用$ scope.gridOptions.api.setRowData(data)的函数,但出现错误
“未捕获的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
最佳答案
该错误表明api不存在。您确定执行此调用之前已实例化$ scope.gridOptions吗?