Giter Site home page Giter Site logo

grid's Introduction

Drag and drop library for a two-dimensional resizable and responsive list of items

Demo: http://ubervu.github.io/grid/

The GridList library is split into two roles:

  1. An agnostic GridList class that manages the two-dimensional positions from a list of items within a virtual matrix
  2. A jQuery plugin built on top of the GridList class that translates the generic items positions into responsive DOM elements with drag and drop capabilities

GridList class

var gridList = new GridList(items, {rows: 3});

Here are the main functions of the GridList class:

  • findPositionForItem: Generate new positions inside a 2d grid. The positioning algorithm places items in columns, starting from left to right, going through each column top to bottom
  • resize: Convert item positions from one grid size to another, maintaining as much of their order as possible
  • moveItemToPosition: Handle collisions when moving an item over another
  • resizeItem: Resize an item and reposition colliding items around. TODO: Currently only the width of an item (w) can be resized
  • getChangedItems: Compare a list of items with that of a GridList instance and return the changed items only (diff). Useful when updating item sizes and positions in a persistent medium (e.g. syncing grid to db with minimum payload)

The size of an item is expressed using the number of cols and rows it takes up within the grid (w and h). The position of an item is expressed using the col and row position within the grid (x and y)

An item is an object of structure:

{
  w: 3, h: 1,
  x: 0, y: 1
}

$.fn.gridList

$('.my-list').gridList({rows: 3});

The jQuery plugin has two main functions:

  • Render the GridList on top of a list of DOM elements. The list items are expected to have data-w and data-h attributes, and optionally data-x and data-y (if their positions have been previously generated and persisted)
  • Drag and drop capabilities

The rendered list is responsive to its parent container, meaning that the width and height of the items are calculated based on the container height divided by the number of grid rows.

FAQ: Why not gridster?

  • Their README reads Ducksboard is no longer active in their development. There are a few notable forks but it's hard to assert their reliability.
  • gridster works vertically and our design is horizontal. We instigated a gridster pull request that attempted to make gridster work both ways and it didn't seem to stabilize any time soon, plus the code was too complex to approach. Our lib ended up having less than 5 times fewer code.
  • gridster collisions are very basic, we pushed towards better UX and found alternative ways for dealing with collisions.
  • We wanted out-of-the-box responsiveness, and the entire grid system was build fluid, relative to any parent container.
  • We needed the grid logic to be a DOM-less lib outside the jQuery plugin. This allows us to compute grid positions on the server-side and run kick-ass fast tests with Node.
  • Another more particular thing we needed was widgets that had height=0, which means they stretch on however many rows a grid has. We show timelines like this. The same can be easily adapted for width in vertical grids.

Please check demo page or code directly for investigating these assumptions.

grid's People

Contributors

ovidiuch avatar valentinzberea avatar catalinmiron avatar mishu- avatar

Watchers

Bogdan Tănase avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.