Dashgrid
:honeybee: A pure javascript high performance grid
Install / Use
/learn @alajmo/DashgridREADME
Dashgrid
A highly customizable drag-and-drop grid built on pure es6 with no external dependencies. Inspired by gridster and angular-gridster and other excellent grid systems.
Don't use in production just yet! Check out demo in the meantime!
Motivation
As far as I know there isn't a grid system that is dependency free, maintained actively, and customizable to the core.
Installation
Either via npm:
npm install dashgrid
or download the dist/dashgrid.js (dashgrid.min.js).
Quick Start
Include the dashgrid.js file either via html, commonjs or es6 syntax.
// Wrapped in DOMContentLoaded to make sure DOM is loaded before Grid.
document.addEventListener('DOMContentLoaded', function() {
var boxes = [
{'row': 1, 'column': 1, 'rowspan': 1, 'columnspan': 1}
];
var options = {
boxes: boxes,
floating: true
};
var element = document.getElementById('grid');
var grid = Grid(element, options);
});
API
Methods
- updateBox
- insertBox
- removeBox
- refreshGrid
Events
- dragStart
- dragging
- dragEnd
- resizeStart
- resizing
- resizeEnd
Properties
Default Configuration
var gridOptions = {
rowHeight: 'auto',
numRows: 6,
minRows: 6,
maxRows: 10,
columnWidth: 'auto',
numColumns: 6,
minColumns: 6,
maxColumns: 10,
xMargin: 20,
yMargin: 20,
defaultBoxRowspan: 2,
defaultBoxColumnspan: 1,
minRowspan: 1,
maxRowspan: 9999,
minColumnspan: 1,
maxColumnspan: 9999,
liveChanges: true,
draggable: {
enabled: true,
handles: 'auto',
dragStart: function () {},
dragging: function () {},
dragEnd: function () {}
},
resizable: {
enabled: true,
handles: ['n', 'e', 's', 'w', 'ne', 'se', 'sw', 'nw'],
handleWidth: 10,
resizeStart: function () {},
resizing: function () {},
resizeEnd: function () {}
},
scrollSensitivity: 20,
scrollSpeed: 10,
snapbacktime: 300,
displayGrid: true
};
Miscellaneous
Grid Width and Height
If rowHeight / columnWidth is set to 'auto', then the grid height / width is set to that of the parent element. rowHeight then becomes gridHeight / numRows + yMargins and columnWidth gridWidth / numColumns + xMargins.
If rowHeight / columnWidth is set to a number, then the grid height is set to:
gridHeight = numRows * rowHeight
and the grid width is set to:
gridWidth = numColumns * columnWidth
Styling
If you want another design on the box, drag handlers, resize handlers, the placeholder box (the shadow box shown when dragging / resizing a box) you can edit these to your liking.
The only css done in Dashgrid is the necessary positioning.
The DOM structure of dashgrid is:
<div class="dashgrid">
<!-- Boxes -->
<div class="dashgrid-boxes">
<div class="dashgrid-box">
<div class="content-element"></div>
<div class="dashgrid-box-resize-handle-n"></div>
<div class="dashgrid-box-resize-handle-e"></div>
<div class="dashgrid-box-resize-handle-w"></div>
<div class="dashgrid-box-resize-handle-s"></div>
<div class="dashgrid-box-resize-handle-ne"></div>
<div class="dashgrid-box-resize-handle-nw"></div>
<div class="dashgrid-box-resize-handle-se"></div>
<div class="dashgrid-box-resize-handle-sw"></div>
</div>
</div>
<!-- Shadow Box -->
<div class="dashgrid-shadow-box"></div>
<!-- Grid Lines -->
<div class="dashgrid-grid-lines"></div>
<!-- Grid Centroids -->
<div class="dashgrid-grid-centroids"></div>
</div>
The way z-index works in this case is:
- dashgrid: 1000
- dashgrid-box: 1003
- moving dashgrid-box: 1004
- dashgrid-shadow-box: 1002
- dashgrid-box-resize-handle: 1003
- dashgrid-grid-lines: 1001
- dashgrid-grid-centroids: 1001
Inspiration
- gridlist
- Packery
- angular gridster
- gridster
Related Skills
node-connect
345.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
104.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
