angular-gridster2
Angular2 implementation of angular-gridster Demo
Angularjs 1.x library is here
Install
npm install angular-gridster2 --save
Should work out of the box with webpack, respectively angular-cli.
import {GridsterModule} from 'angular-gridster2';
@NgModule({
imports: [GridsterModule],
...
})
How to use
<gridster [options]="options">
<gridster-item [item]="item" *ngFor="let item of dashboard">
</gridster-item>
</gridster>
Initialize the demo dashboard
options: GridsterConfig;
dashboard: Array<Object>;
ngOnInit() {
this.options = {
gridType: 'fit',
compactUp: true,
compactLeft: true,
itemChangeCallback: this.itemChange.bind(this),
margin: 10,
outerMargin: true,
draggable: {
enabled: true,
stop: this.eventStop.bind(this)
},
resizable: {
enabled: true,
stop: this.eventStop.bind(this)
},
swap: true
};
this.dashboard = [
{cols: 2, rows: 1, y: 0, x: 0},
{cols: 2, rows: 2, y: 0, x: 2},
{cols: 1, rows: 1, y: 0, x: 4},
{cols: 1, rows: 1, y: 0, x: 5},
{cols: undefined, rows: undefined, y: 1, x: 0},
{cols: 1, rows: 1, y: undefined, x: undefined},
{cols: 2, rows: 2, y: 1, x: 5, minItemRows: 2, minItemCols: 2},
{cols: 2, rows: 2, y: 2, x: 0, maxItemRows: 2, maxItemCols: 2},
{cols: 2, rows: 1, y: 2, x: 2, dragEnabled: true, resizeEnabled: true},
{cols: 1, rows: 1, y: 2, x: 4, dragEnabled: false, resizeEnabled: false},
{cols: 1, rows: 1, y: 3, x: 4, initCallback: this.itemInit.bind(this)}
];
}
changedOptions() {
this.options.optionsChanged();
}
eventStop(item, scope) {
console.info('eventStop', item, scope);
}
itemChange(item, scope) {
console.info('itemChanged', item, scope);
}
itemInit(item) {
console.info('itemInitialized', item);
}
Default Options:
import {GridsterConfig} from './gridsterConfig.interface';
const GridsterConfigService: GridsterConfig = {
gridType: 'fit',
compactUp: false,
compactLeft: false,
mobileBreakpoint: 640,
minCols: 1,
maxCols: 100,
minRows: 1,
maxRows: 100,
defaultItemCols: 1,
defaultItemRows: 1,
maxItemCols: 50,
maxItemRows: 50,
minItemCols: 1,
minItemRows: 1,
margin: 10,
outerMargin: true,
scrollSensitivity: 10,
scrollSpeed: 20,
itemChangeCallback: undefined,
draggable: {
enabled: false,
stop: undefined
},
resizable: {
enabled: false,
handles: {
s: true,
e: true,
n: true,
w: true,
se: true,
ne: true,
sw: true,
nw: true
},
stop: undefined
},
swap: true
};
License
The MIT License
Copyright (c) 2017 Tiberiu Zuld