我是angularjs技术的新手.我正在使用ag-grid并想要动态显示列
我的json数据是:
[{Date:'12-12-2015',Name:'ammu',mark:20},{Date:'12-12-2015',Name:'appu',mark:24},{Date:'12-12-2015',Name:'anu',mark:27},{Date:'13-12-2016',Name:'ammu',mark:23},{Date:'13-12-2015',Name:'anu',mark:20}]
我的预期产出是 预期产出
现有守则如下
$scope.gridOptions = { columnDefs: [], enableFilter: true, rowData: [], rowSelection: 'multiple', rowDeselection: true }; $scope.customColumns = []; Getdetails(); function Getdetails() { masterdataFactory.Getdetails() .success(function (Student) { f (Student.length != 0) { for(var i=0;i现有产出在现有产出下方给出
如何从现有输出到达我的预期输出
1> Suny Saju..:首先安排json数据
[{Date:'12-12-2015',ammu:20,appu:24,anu:27},{Date:'13-12-2016' ammu:23,anu:20}]为此,我正在使用以下代码
function generateChartData() { var chartData = [], categories = {}; debugger; for ( var i = 0; i网格选项如下:
$scope.gridOptions = { columnDefs: coldef(), enableFilter: true, rowData: [], rowSelection: 'multiple', rowDeselection: true, enableColResize: true, } }; $scope.gridOptions.columnDefs = $scope.customColumns; $scope.gridOptions.rowData =generateChartData(); $scope.gridOptions.rowData = generateChartData(); }列定义是动态的,如下所示
function coldef() { for(var i=0;i在此标头中是一个数组。该数组包含不同的学生姓名
var headers=new Array(); headers[0]="DATE"; var Names= Student.map(function (item) { return item.Name}); Names= Names.filter(function (v, i) { return Names.indexOf(v) == i; }); for(var i=1;i<=Names.length;i++) { headers[i]=Names[i-1]; }