大佬教程收集整理的这篇文章主要介绍了angularjs – 当griddata与以前显示的griddata的列数不同时,如何刷新ng网格,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的控制器是:
var app = angular.module('myApp',['ngGrid']); app.controller('GridExampleCtrl',function ($scope,$http,$timeout) { $scope.myData = []; $scope.grid1 = [{name: "grid1a",age: 50},{name: "grid1b",age: 43},{name: "grid1c",{name: "grid1d",age: 29},{name: "grid1e",age: 34}]; $scope.grid2 = [{lastname: "grid2a",age: 50,state:'Idaho'},{lastname: "grid2b",age: 43,state:'NewYork'},{lastname: "grid2c",state:'California'},{lastname: "grid2d",age: 29,state:'Arizona'},{lastname: "grid2e",age: 34,state:'Utah'}]; $scope.gridSels = [ {GridSelId : 1,GridSelName : 'Grid 1' },{GridSelId : 2,GridSelName : 'Grid 2' } ] $scope.gridoptions = { data: 'myData',enablecolumnResize: true,showGroupPanel: true,//pagingOptions: $scope.pagingOptions }; $scope.display = function(){ console.log("User SELEcted grid : " + $scope.gridSELEctedId); if ($scope.gridSELEctedId == 1) { $scope.myData = $scope.grid1; } else { $scope.myData = $scope.grid2; } }; });
和css看起来像:
.gridStyle { border: 1px solid rgb(212,212,212); width: 800px; height: 400px; }
$scope.colDefs = []; $scope.$watch('myData',function() { $scope.colDefs = []; angular.forEach(Object.keys($scope.myData[0]),function(key){ $scope.colDefs.push({ field: key }); }); } ); $scope.gridoptions = { data: 'myData',columnDefs: 'colDefs',enablecolumnResize: false,showGroupPanel: true };
这是一个工作的朋友,用你的例子来展示它:
http://plnkr.co/edit/w1DLtS
以上是大佬教程为你收集整理的angularjs – 当griddata与以前显示的griddata的列数不同时,如何刷新ng网格全部内容,希望文章能够帮你解决angularjs – 当griddata与以前显示的griddata的列数不同时,如何刷新ng网格所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。