AngularJs:使用ag-grid的$ scope.grid.api.setRowData()不起作用 [英] AngularJs : using ag-grid's $scope.grid.api.setRowData() does not work
问题描述
因此,我分叉了这个简单的农业网格演示Plunker ,分叉的版本是< a href = https://plnkr.co/edit/gAFp3P9IiFVUbI1M rel = nofollow noreferrer>此处。
So, I forked this simple ag-grid demo Plunker and the forked version is here.
唯一的变化是旧代码为 ag-grid
静态分配行数据,而我的fork尝试使用API动态分配i。
i
old:
The only change is that the old code statically assigned the row data for the ag-grid
while my fork tries to assign i dynamically, using the API.
i
old:
var rowData = [
{make: "Toyota", model: "Celica", price: 35000},
{make: "Ford", model: "Mondeo", price: 32000},
{make: "Porsche", model: "Boxter", price: 72000}
];
// let the grid know which columns and what data to use
var gridOptions = {
columnDefs: columnDefs,
rowData: rowData,
onGridReady: function () {
gridOptions.api.sizeColumnsToFit();
}
};
新功能:
var rowData = [
{
make: "Toyota",
model: "Celica",
price: 35000
},
{
make: "Ford",
model: "Mondeo",
price: 32000
},
{
make: "Porsche",
model: "Boxter",
price: 72000
}
];
$scope.grid = {
columnDefs: columnDefs,
rowData: [],
rowSelection: 'single'
};
$scope.grid.api.setRowData(rowData);
都在我的Plunker中,并在 localhost $ c $上尝试c>,
ag-grid
不会出现。
Both in my Plunker, and trying this on localhost
, the ag-grid
does not appear.
我做错了什么?
[更新]我想每次用户单击按钮时都从服务器获取数据,而不仅仅是在网格准备好时,并且
[Update] I want to get the data from a server every time the user clicks a button, not just when the grid is ready, and assign the grid's rowData using it's api.
[Upperdate]我在localhost上注意到,尽管 $ scope.gridOptions
已定义, $ scope.gridOptions.api
未定义
[Upperdate] I just noticed on localhost that although $scope.gridOptions
is defined, $scope.gridOptions.api
is undefined
推荐答案
好,我解决了。静态与静态之间的区别动态网格。参见此柱塞。
ok, I solved it. It is the difference between static & dynamic grid. See this Plunker.
更改HTML到< div id = myGrid class = ag-fresh style = height:100px;>< / div>
(删除 ag-grid = grid
),然后在控制器中:
Change the HTML to <div id="myGrid" class="ag-fresh" style="height: 100px;"></div>
(removing the ag-grid="grid"
), and then, in the controller:
var currentCandidatesGridDiv = document.querySelector('#myGrid');
new agGrid.Grid(currentCandidatesGridDiv, $scope.grid);
$scope.grid.api.setRowData(rowData);
我要这个是为了帮助上一个问题,并且对自己有所帮助-只是希望我也对其他人有所帮助:-)
I was asking this to help with a previous question, and have helped myself a little - just hope that I helped someone else too :-)
这篇关于AngularJs:使用ag-grid的$ scope.grid.api.setRowData()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!