[英]Rows from server not showing in Ag-grid?
So I'm using Ag-grid as a table technology to display data I retrieved from a server. 因此,我将Ag-grid用作表技术来显示从服务器检索到的数据。
I send a query to the backend like so: 我将查询发送到后端,如下所示:
var query = QueryService.getQuery();
if (typeof vm.queryDimensions !== 'undefined' && vm.queryDimensions.keepSorted) {
query['query'] = vm.queryDimensions.dim;
}
query['start'] = vm.pageMarker || 0;
query['count'] = vm.numPerPage;
query['sortBy'] ='date';
query['sortOrder'] = 'desc';
Where I indicate the what index to start from, and how much data to retrieve. 我在哪里指示从哪个索引开始,以及检索多少数据。
The response has 2 parts: The actual data which is an array of objects with the length equal to whatever query['count'] is, and the total number of results found. 响应分为两部分:实际数据,即对象数组,其长度等于任何query ['count']的长度,以及找到的结果总数。
I have the columns working fine. 我的列工作正常。 It's stored in a variable called colDefs.
它存储在名为colDefs的变量中。
After I get the data with my service, this is what I do, based on the Ag-grid docs: 在通过服务获取数据后,这就是我根据Ag-grid文档所做的事情:
DataService.getEventsData(query).then(function(res){
vm.pageMarker = res.results.length + 1;
createTableSource(res)
})
}
function createTableSource(data){
var source = {
//rowCount: data.resultsFound,
pageSize: vm.numPerPage,
getRows: function(params) {
params.startRow = 0;
params.endRow = vm.pageMarker;
var formattedData = formatData(data.results);
console.log(formattedData);
params.successCallback(formattedData);
}
};
vm.gridOptions.api.setDatasource(source);
}
function formatData(tableData){
var formattedTableData = [];
console.log(tableData);
angular.forEach(tableData, function(v,k){
var rowObj = {};
angular.forEach(colDefs, function(i,j){
if(i.field === 'date'){
rowObj['date'] = v.date
}
})
formattedTableData.push(rowObj);
});
console.log(formattedTableData);
return formattedTableData;
}
However, when I check my table, it only shows the columns and the pagination options at the bottom, but none of my actual date. 但是,当我检查表格时,它仅在底部显示列和分页选项,而没有显示我的实际日期。 I don't know what else I'm missing with my data.
我不知道我的数据还缺少什么。
I fixed the issue. 我解决了这个问题。 It was an issue with the height and width I was giving my table.
我给桌子放的高度和宽度是个问题。 It works now.
现在可以使用了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.