Git Product home page Git Product logo

angular-fluid-grid's Introduction

angular-fluid-grid

AngularJS directive providing a nice fluid dashboard functionality.

Tested with FF, Chrome, Safari on OSX and FF, Chrome, IE9 on Windows7.

##Demo

See Live demo

##Requirements

AngularJS only!

##How to use

Here is an example of the default usage:

    <div fluid-grid>
        <ul>
            <li fluid-grid-item="item" ng-repeat="item in items"></li>
        </ul>
    </div>

Which expects a scope setup like the following:

    // IMPORTANT: Items should be placed in the grid in the order in which they should appear.
    // In most cases the sorting should be by row ASC, col ASC

    // these map directly to fluidGridItem directive options
    $scope.items = [
        { sizeX: 2, sizeY: 1, row: 0, col: 0 },
        { sizeX: 2, sizeY: 2, row: 0, col: 2 },
        { sizeX: 1, sizeY: 1, row: 0, col: 4 },
        { sizeX: 1, sizeY: 1, row: 0, col: 5 },
        { sizeX: 2, sizeY: 1, row: 1, col: 0 },
        { sizeX: 1, sizeY: 1, row: 1, col: 4 },
        { sizeX: 1, sizeY: 2, row: 1, col: 5 },
        { sizeX: 1, sizeY: 1, row: 2, col: 0 },
        { sizeX: 2, sizeY: 1, row: 2, col: 1 },
        { sizeX: 1, sizeY: 1, row: 2, col: 3 },
        { sizeX: 1, sizeY: 1, row: 2, col: 4 }
    ];

Configuration

Via Scope

Simply pass your desired options to the fluid-grid directive

    $scope.fluidGridOpts = {
		columns: 6, // the width of the grid, in columns
		pushing: true, // whether to push other items out of the way on move or resize
		floating: true, // whether to automatically float items up so they stack (you can temporarily disable if you are adding unsorted items with ng-repeat)
		width: 'auto', // can be an integer or 'auto'. 'auto' scales fluid-grid to be the full width of its containing element
		colWidth: 'auto', // can be an integer or 'auto'.  'auto' uses the pixel width of the element divided by 'columns'
		rowHeight: 'match', // can be an integer or 'match'.  Match uses the colWidth, giving you square widgets.
		margins: [10, 10], // the pixel distance between each widget
		outerMargin: true, // whether margins apply to outer edges of the grid
		isMobile: false, // stacks the grid items if true
		mobileBreakPoint: 600, // if the screen is not wider that this, remove the grid layout and stack the items
		mobileModeEnabled: true, // whether or not to toggle mobile mode when screen width is less than mobileBreakPoint
		minColumns: 1, // the minimum columns the grid must have
		minRows: 2, // the minimum height of the grid, in rows
		maxRows: 100,
		defaultSizeX: 2, // the default width of a fluid-grid item, if not specifed
		defaultSizeY: 1, // the default height of a fluid-grid item, if not specified
		resizable: {
            enabled: true,
            handles: ['s', 'e', 'n', 'w', 'se', 'ne', 'sw', 'nw'],
            start: function(event, $element, item) {}, // optional callback fired when resize is started,
            resize: function(event, $element, item) {}, // optional callback fired when item is resized,
            stop: function(event, $element, item) {} // optional callback fired when item is finished resizing
		},
		draggable: {
            enabled: true, // whether dragging items is supported
            handle: '.my-class', // optional selector for drag handle (either element tag or class attribute)
            start: function(event, $element, item) {}, // optional callback fired when drag is started,
            drag: function(event, $element, item) {}, // optional callback fired when item is moved,
            stop: function(event, $element, item) {} // optional callback fired when item is finished dragging
		},
		dynamicContent: { // optional dynamic content to be injected (see below for more information)
		    name: 'some-attr', // item's attribute holding the name of the custom directive (required)
		    selector: '.some-class' // element tag or class name where dynamic content will be injected (required)
		}
    };

Via Constant

You can also override the default configuration site wide by modifying the fluidGridConfig constant

    angular.module('yourApp').run(['fluidGridConfig', function(fluidGridConfig) {
        fluidGridConfig.width = 1000;
    }]);

Dynamic Content

To add (inject) a dynamic content like for example your own directive, use the dynamicContent option. Just provide the name of item's attribute that holds the name of your custom directive and the selector (html element or class name) which marks the position where your directive will be placed. Sounds complicated? OK, let's try with an example.

Given this:

// somewhere in your controller
this.fluidGridOpts = {
    dynamicContent: {
        name: 'type',
        selector: '.put-my-content-here'
    }
};

this.items = [{
    sizeX: 2,
    sizeY: 1,
    row: 0,
    col: 0,
    name: 'Widget 1',
    type: 'my-custom-directive'
}];
    <div fluid-grid="ctrl.fluidGridOpts">
        <ul>
            <li fluid-grid-item="item" ng-repeat="item in ctrl.standardItems">
                <div class="put-my-content-here">
                    {{item.row}} , {{item.col}}
                </div>
            </li>
        </ul>
    </div>

and your custom directive:

    angular.directive('myCustomDirective', function () {
        return {
            restrict: 'A',
            template: '<div>My fantastic directive shows item\'s row {{item.row}} and col {{item.col}}</div>',
            scope: {
                item: '='
            }
        };
    });

you get following:

    <div fluid-grid="ctrl.fluidGridOpts">
        <ul>
            <li fluid-grid-item="item" ng-repeat="item in ctrl.standardItems">
                <div class="put-my-content-here ng-scope ng-isolate-scope" my-custom-directive="" item="item">
                    <div class="ng-binding">
                        <div>My fantastic directive shows item's row 0 and col 0</div>
                    </div>
                </div>
            </li>
        </ul>
    </div>

##Installation

    bower install angular-fluid-grid

Then, import the following in your HTML alongside angular:

    <link rel="stylesheet" href="dist/angular-fluid-grid.min.css" />
    <script src="dist/angular-fluid-grid.js"></script>

TO DO

Documentation

Tests (Oh my ...)

Option handle to fluid-grid-item (like jQuery-UI)

angular-fluid-grid's People

Contributors

sekib avatar sekibomazic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

weldelmongi

angular-fluid-grid's Issues

File name inconsistency

The dependency files listed in the example README.md reference to include angular-fluid-grid.min.css and angular-fluid-grid.js. In the repository, these files are named fluid-gris.min.css and fluid-grid.js respectively.

<script src="dist/angular-fluid-grid.js"></script>

placing new item in row other than first row when first row is empty

I have a grid with 2 rows and 4 columns. I am dynamically creating items based on users choices. If a user wants to start adding items to an empty grid and the first item is on the 2nd row. My item record looks like this
item = { row: 1, col: 2, sizeX: 1, sizeY: 1 }
When the item renders in grid it shows with the row as 0 not 1. Is there a way to keep the grid from forcing the item into the first row if row is empty?

image

Adding items dynamically

Thanks for this great angular-grid. I really like it.

I just tried to add an item dynamically by just adding it to the items-array. That works like a charm.
But the grid is not immediately redrawn, so that the new item does not show up only until I force a redraw by moving the other items or resizing.
How can I issue a "redraw" after changing the items-array?

Thanks again and kind regards
Stefan

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.