angular-gridster2

import { NgForOf, NgIf } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
OnInit,
ViewEncapsulation
} from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';

import { MatSelectModule } from '@angular/material/select';

import {
CompactType,
DisplayGrid,
Draggable,
GridsterComponent,
GridsterConfig,
GridsterItem,
GridsterItemComponent,
GridType,
PushDirections,
Resizable

} from 'angular-gridster2';

 

interface Safe extends GridsterConfig {
draggable: Draggable;
resizable: Resizable;
pushDirections: PushDirections;
}

 

@Component({
selector: 'app-general',
templateUrl: './home.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
standalone: true,
imports: [
FormsModule,
NgForOf,
NgIf,
MatButtonModule,
MatCheckboxModule,
MatIconModule,
MatInputModule,
MatSelectModule,
GridsterComponent,
GridsterItemComponent
]
})
export class HomeComponent implements OnInit {
options: Safe;
dashboard: Array<GridsterItem>;
ngOnInit(): void {
this.options = {
gridType: GridType.Fit,
compactType: CompactType.None,
margin: 10,
outerMargin: true,
outerMarginTop: null,
outerMarginRight: null,
outerMarginBottom: null,
outerMarginLeft: null,
useTransformPositioning: true,
mobileBreakpoint: 640,
useBodyForBreakpoint: false,
minCols: 1,
maxCols: 100,
minRows: 1,
maxRows: 100,
maxItemCols: 100,
minItemCols: 1,
maxItemRows: 100,
minItemRows: 1,
maxItemArea: 2500,
minItemArea: 1,
defaultItemCols: 1,
defaultItemRows: 1,
fixedColWidth: 105,
fixedRowHeight: 105,
keepFixedHeightInMobile: false,
keepFixedWidthInMobile: false,
scrollSensitivity: 10,
scrollSpeed: 20,
enableEmptyCellClick: false,
enableEmptyCellContextMenu: false,
enableEmptyCellDrop: false,
enableEmptyCellDrag: false,
enableOccupiedCellDrop: false,
emptyCellDragMaxCols: 50,
emptyCellDragMaxRows: 50,
ignoreMarginInRow: false,
draggable: {
enabled: true
},
resizable: {
enabled: true
},
swap: false,
pushItems: true,
disablePushOnDrag: false,
disablePushOnResize: false,
pushDirections: { north: true, east: true, south: true, west: true },
pushResizeItems: false,
displayGrid: DisplayGrid.Always,
disableWindowResize: false,
disableWarnings: false,
scrollToNewItems: false
};
this.dashboard = [
{ cols: 2, rows: 1, y: 0, x: 0 },
{ cols: 2, rows: 2, y: 0, x: 2, hasContent: true },
{ cols: 1, rows: 1, y: 0, x: 4 },
{ cols: 1, rows: 1, y: 2, x: 5 },
{ cols: 1, rows: 1, y: 1, x: 0 },
{ cols: 1, rows: 1, y: 1, x: 0 },
{
cols: 2,
rows: 2,
y: 3,
x: 5,
minItemRows: 2,
minItemCols: 2,
label: 'Min rows & cols = 2'
},
{
cols: 2,
rows: 2,
y: 2,
x: 0,
maxItemRows: 2,
maxItemCols: 2,
label: 'Max rows & cols = 2'
},
{
cols: 2,
rows: 1,
y: 2,
x: 2,
dragEnabled: true,
resizeEnabled: true,
label: 'Drag&Resize Enabled'
},
{
cols: 1,
rows: 1,
y: 2,
x: 4,
dragEnabled: false,
resizeEnabled: false,
label: 'Drag&Resize Disabled'
},
{ cols: 1, rows: 1, y: 2, x: 6 }
];
}
changedOptions(): void {
if (this.options.api && this.options.api.optionsChanged) {
this.options.api.optionsChanged();
}
}
removeItem($event: MouseEvent | TouchEvent, item): void {
$event.preventDefault();
$event.stopPropagation();
this.dashboard.splice(this.dashboard.indexOf(item), 1);
}
addItem(): void {
this.dashboard.push({ x: 0, y: 0, cols: 1, rows: 1 });
}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值