Posted 21 March 2018, 1:57 am EST - Updated 3 October 2022, 11:32 am EST
Hello everyone! I’d to know how can I initialize FlexGrid object in my controller and then use it in HTML? Because I need to build up my own headers and the whole table with data from JSON.
How my project looks now:
index.html:
<div ng-controller="MyJSONController">
<wj-flex-grid items-source="table_source"
items-source-changed="itemsSourceChanged(s,e)">
</wj-flex-grid>
</div>
- “[li][/li]”
controller :
var MyJSONController = function ($scope, $http) {
$http.get('query.json').success(function (data) {
$scope.query = data;
$scope.table_source = new wijmo.collections.CollectionView(setData(data));
})
$scope.itemsSourceChanged = function(sender, args) {
sender.autoSizeColumns();
};
function setData(json_string) {
var data = new wijmo.collections.ObservableArray();
for(var i = 1; i <= getMaxRow(json_string); i++) {
var row_data = new wijmo.collections.ObservableArray();
for(var j = 1; j <= getMaxCol(json_string); j++) {
json_string.Cells.forEach(function (element) {
if(parseInt(element.Row) == i && parseInt(element.Col) == j){
row_data.push(element.Value);
}
});
}
data.push(row_data);
}
return data;
}
//Method to get max amount of Cols
function getMaxCol(json_string){
var maxCol = 0;
json_string.Cells.forEach(function (element) {
if(parseInt(element.Col) > maxCol) maxCol = parseInt(element.Col);
});
return maxCol;
}
//Method to get max amount of Rows
function getMaxRow(json_string){
var maxRow = 0;
json_string.Cells.forEach(function (element) {
if(parseInt(element.Row) > maxRow) maxRow = parseInt(element.Row);
});
return maxRow;
}
}
Result:
JSON:
https://jsonblob.com/f6f59f22-2d17-11e8-9126-d5ef59fe6a2c
As you see my headers from JSON aren’t located in headers.