Repository navigation
Drag
Demo: Drag.
options: GridsterConfig = {
draggable: {
enabled: true,
delayStart: 0,
start: (item, itemComponent, event) => console.info('drag start', item),
stop: (item, itemComponent, event) => console.info('drag stop', item)
}
};-
dragEnabledon an item overridesdraggable.enabled. - Dragging is disabled in the mobile layout.
- While dragging, the item gets the
gridster-item-movingclass and the target position is shown by<gridster-preview>. - After the drop the grid updates
x/yof the moved item (and of pushed or swapped items) and emitsitemChange.
By default a drag starts anywhere on the item, except:
- the resize handles;
- inside elements with the
draggable.ignoreContentClassclass (defaultgridster-item-content), which is also the way to keep text selectable and inputs usable.
<gridster-item [item]="item">
<header>Drag me</header>
<div class="gridster-item-content">Selectable text, buttons and inputs</div>
</gridster-item>To drag only from handles, set ignoreContent: true and mark the handles with dragHandleClass (default drag-handler):
draggable: { enabled: true, ignoreContent: true, dragHandleClass: 'drag-handler' }<gridster-item [item]="item">
<button class="drag-handler">⠿</button>
<app-widget [config]="item" />
</gridster-item>Alternatively, stop the event yourself: (mousedown)="$event.stopPropagation()" (touchstart)="$event.stopPropagation()".
delayStart (milliseconds) requires holding the item before the drag starts, so the page can still be scrolled with a swipe. Moving more than a few pixels during the delay cancels the drag.
draggable.stop may return a promise: resolve it to keep the new position, reject it to move the item (and any pushed or swapped item) back.
draggable: {
enabled: true,
stop: (item, itemComponent) => this.layoutService.canMove(item) // Promise<void>
}In scrolling grids, the grid scrolls when the pointer gets within scrollSensitivity pixels (default 10) of an edge, or leaves the grid, and stops when the pointer moves back.
| Option | Default | Description |
|---|---|---|
scrollSensitivity |
10 |
Distance from the edge in pixels (unscaled, following the writing direction in RTL) |
scrollSpeed |
20 |
Pixels scrolled every 40 ms |
disableScrollVertical |
false |
Turn off vertical auto-scroll |
disableScrollHorizontal |
false |
Turn off horizontal auto-scroll |
Auto-scroll moves the scroll position of <gridster>: with setGridSize: true the page does not scroll while dragging, and the item stays under the pointer.
Scrolling the grid yourself during a drag or a resize, with the wheel or a trackpad, also keeps the item or its edge under the pointer. A drag the browser turns into a native one, which happens when the pointer starts on selected text, is stopped instead of leaving the item floating.
enableBoundaryControl: true keeps dragged and resized items inside the grid edges.
With swap (on by default) dropping an item over another one swaps them when both fit; with pushItems other items are moved away. See Push and Swap.
To let items overlap on drop instead, turn both off and enable dropOverItems:
options: GridsterConfig = {
swap: false,
pushItems: false,
draggable: {
enabled: true,
dropOverItems: true,
dropOverItemsCallback: (source, target, gridster) => this.merge(source, target)
}
};Items cannot be dragged between grids. To add items by dragging something from outside, use HTML5 drag and drop with enableEmptyCellDrop, see Empty Cells.
MIT License. Originally created by Tiberiu Zuld as angular-gridster2. These pages are generated from the wiki/ folder of the repository: propose changes with a pull request.
Start
Guides
- Grid Types
- Grid Size and Margins
- Items
- Drag
- Resize
- Push and Swap
- Compaction
- Empty Cells
- Multi-Layer
- Responsive and Mobile
- RTL
- Dynamic Widgets
- Saving and Restoring Layouts
Reference
Help