我使用 angularjs、kendoui 图表和 angular gridster ( https://github.com/ManifestWebDesign/angular-gridster ) 创建了一个仪表板。
所以我有一个功能可以添加一个带有如下图表的网格: -
// 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
我可以将此对象保存到后端并获取值。我为每个图表设置 row 和 col 值如下,因为 sizeX 和 sizeY 值恒定为 3 和 2。
- 第一个图表行:0 和列:0
- 第二个图表行:0 和 col:3
- 第三个图表行:2 和列:0
- 第四个图表行:2 和列:3
我在以下页面上提到并搜索了解决方案:-
所以现在我的 HTML 如下所示,所以我设置了 row 和 col 值:-
<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>
我的 gridster 配置如下:-
$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
}
};
当我从后端获取 gridster 项目时,它们是随机顺序的,并且 gridster 不会根据 row 和 col 值对齐它们。