GithubHelp home page GithubHelp logo

dodohee / ngx-widget-grid Goto Github PK

View Code? Open in Web Editor NEW

This project forked from envyn/ngx-widget-grid

0.0 1.0 0.0 2.01 MB

Angular 2.x or in general ng-x module for dashboards

Home Page: https://envyn.github.io/ngx-widget-grid

License: MIT License

JavaScript 3.29% TypeScript 82.18% HTML 9.81% CSS 4.72%

ngx-widget-grid's Introduction

ngx-widget-grid

codebeat badge

A flexible grid layout for responsive dashboards

This library got its inspiration from angular-widget-grid and has been written as a pure Angular 2.x [+] module.

Installation

Install with npm:

$ npm install ngx-widget-grid

or with yarn

$ yarn add ngx-widget-grid

Add the ngx-widget-grid module as a dependency to your application module:

import { NgxWidgetGridModule } from 'ngx-widget-grid';

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    ...
    NgxWidgetGridModule,
    ...
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Usage

Minimal Example

<ngx-widget-grid [rows]="4" [columns]="5" [highlightNextPosition]="false"
                 [showGrid]="true" (widgetPositionChange)="onWidgetChange($event)">
  <ngx-widget [(position)]="{top: 2,left: 2,height: 1,width: 1}"
              [movable]="true" [resizable]="true">
    <div style="height:100%;width:100%; display:flex;">
      <div style="height:100%;width:100%; padding:10px; background-color: rgb(140, 198, 0);">
      </div>
    </div>
  </ngx-widget>
</ngx-widget-grid>

Minimal Example

Adding Traits

Widgets

position
<ngx-widget [(position)]="widget.position"...>

You can bind the position of the widget to data received from server so that even if the widget is moved, the new positions are always updated in the widget configuration.

movable
<ngx-widget [movable]="true" [(position)]="widget.position"...>

If movable is true, users will be able to move the respective widget.

Moving Widgets

resizable
<ngx-widget [resizable]="true" [(position)]="widget.position"...>

If resizable is true, users will be able to resize the respective widget.

Resizing Widgets

Optionally, you can limit the resize directions:

<ngx-widget [resizeDirections]="['NW', 'NE', 'E', 'SW']" [(position)]="widget.position"...>

Restricted Resizing

swapOnMove
<ngx-widget [swapOnMove]="true" [(position)]="widget.position"...>

If swapOnMove is true, dragged widget will swap position and size with the widget over which the current one is dropped. Default is false which means, widget will be placed in the nearest available area.

Grid: Options

showGrid (default: false)
<ngx-grid columns="20" rows="15" [showGrid]="true">

Toggles the gridlines.

Gridlines Enabled

highlightNextPosition (default: false)
<ngx-grid columns="20" rows="15" [highlightNextPosition]="true">

Highlights the largest free area in the grid, if any. This area will be automatically assigned to the next widget with a falsy or conflicting position.

Highlight Next Position (1/2) Highlight Next Position (2/2)

Events

gridFull

The grid emits gridFullevent as true (when grid has been fully occupied) or false when there is still some space left in the grid, so that you can e.g. enable/disable UI elements accordingly.

<ngx-grid columns="20" rows="15" (gridFull)="onGridFull($event)">
function onGridFull(isGridFull) {
    if(isGridFull){
        ...
        //make add widget button disabled
        ...
    }else{
        ...
        //make add widget button enabled
        ...
    }
}
widgetPositionChange

Emitted whenever the position of a widget is changed. The event comes with an attached object argument, which contains the affected widget's index and its newPosition.

<ngx-grid columns="20" rows="15" (widgetPositionChange)="onWidgetChange($event)">

Functions

getNextPosition

getNextPosition is a function you could call to get details about the next available position that is being highlighted as part of highlightNextPosition.

Build (for developers/contributors)

  • Install yarn
  • Install dependencies
    yarn install
  • Run
    yarn start
  • Build
    yarn build
  • Link
    cd dist && yarn link
  • Publish (from repo root directory)
    yarn publish:lib --new-version <version>

License

MIT

ngx-widget-grid's People

Contributors

envyn avatar ky-one avatar

Watchers

CK Park 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.