AngularJs:使用ag

编程入门 行业动态 更新时间:2024-10-11 15:17:17
本文介绍了AngularJs:使用ag-grid的$ scope.grid.api.setRowData()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

因此,我分叉了这个简单的农业网格演示Plunker ,分叉的版本是此处。

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 , 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

本文发布于:2023-11-23 01:10:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619565.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:AngularJs   ag

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!