I have created a dashboard using angularjs, kendoui charts and angular gridster (https://github.com/ManifestWebDesign/angular-gridster).
So I have a function to add a gridster with chart like below :-
// add widget to a dashboard
$scope.addWidget = function () {
// new widget configuration
var newWidget = {
id: $scope.allWidgetData.selectedOption.id,
data_source: {},
config: {
name: $scope.allWidgetData.selectedOption.name,
sizeX: 3,
sizeY: 2,
row: $scope.row,
col: $scope.col
}
};
}
// make api call and save data
I can save this object to backend and get the values too. I am setting row and col values for each chart as follows as the sizeX and sizeY values are constant as 3 and 2.
- First chart row:0 and col:0
- Second chart row:0 and col:3
- Third chart row:2 and col:0
- Fourth chart row:2 and col:3
I referred and searched for solution on below pages :-
So now my HTML is like below so I set row and col values:-
<div gridster="gridsterOptions" ng-if="isShowing(index)">
<ul>
<li gridster-item="widget" ng-repeat="widget in widgetData.availableOptions" row="widget.config.row" col="widget.config.col" style="overflow:hidden;" >
<div class="box">
// kendo ui chart in div
</li>
</ul>
</div>
My gridster configuration is like below :-
$scope.gridsterOptions = {
minRows: 2, // the minimum height of the grid, in rows
maxRows: 100,
columns: 6, // the width of the grid, in columns
colWidth: 'auto', // can be an integer or 'auto'. 'auto' uses the pixel width of the element divided by 'columns'
rowHeight: 'match', // can be an integer or 'match'. Match uses the colWidth, giving you square widgets.
margins: [10, 10], // the pixel distance between each widget
defaultSizeX: 3, // the default width of a gridster item, if not specifed
defaultSizeY: 2, // the default height of a gridster item, if not specified
mobileBreakPoint: 600, // if the screen is not wider that this, remove the grid layout and stack the items
swapping: false,
pushing: true,
floating: false,
resizable: {
enabled: true,
start: function(event, uiWidget, $element) {}, // optional callback fired when resize is started,
resize: function (event, uiWidget, $element) {
}, // optional callback fired when item is resized,
stop: function(event, uiWidget, $element) {
} // optional callback fired when item is finished resizing
},
draggable: {
enabled: true, // whether dragging items is supported
handle: '.box-header', // optional selector for resize handle
start: function(event, uiWidget, $element) {}, // optional callback fired when drag is started,
drag: function(event, uiWidget, $element) {}, // optional callback fired when item is moved,
stop: function(event, uiWidget, $element) {
} // optional callback fired when item is finished dragging
}
};
When I get the gridster items from backend they are in random order and gridster does not align them as per row and col values.