Giter Club home page Giter Club logo

ngx-property-grid's Introduction

NgxPropertyGrid

License: MIT npm version Build Status

A small and simple property grid in angular to view/edit POJOs, excellent if you have a "settings" object you want to give the user to edit (that's why I have created it). Play online.

Dependencies

Usage

  1. Import
    import {PropertyGridModule} from 'ngx-property-grid';
    
    import {NgxTemplateModule} from 'ngx-template';
    If you need animation,you should import BrowserAnimationsModule in your app.module.ts.
  2. Getting Started
    • Html
      • Basic
        <ngx-property-grid [width]="'300px'" [options]="editor"></ngx-property-grid>
      • Template
        <ngx-property-grid [width]="'300px'" [options]="editor">
            <ng-template ngxTemplate="text" let-p>
                <input type="text" [value]="p.value" (change)="p.value = $event.target.value">
            </ng-template>
            <ng-template ngxTemplate="color" let-p>
                <input type="color" [value]="p.value" (change)="p.value = $event.target.value">
            </ng-template>
        </ngx-property-grid>
    • Object options
      export class ExampleEditorOptions {
          @meta({name: 'Font', description: 'The font editor to use', type: SimpleTextEditorComponent, group: 'Editor', hidden: false})
          font = 'Source Code Pro';
      
          @meta({name: 'Font size', group: 'Editor', type: 'number', valueConvert: parseInt})
          fontSize = 14;
      
          @meta({name: 'Font color', group: 'Editor', type: 'color'})
          fontColor = '#51f41c';
      
          @meta({name: 'jQuery', group: 'Plugins', type: 'checkbox'})
          jQuery = true;
      
          @meta({name: 'modernizr', description: 'Whether or not to include modernizr on the page', group: 'Plugins', type: 'checkbox'})
          modernizr = false;
      
          @meta({
              name: 'Framework',
              description: 'Whether to include any additional framework',
              type: 'options',
              options: ['None', {text: 'AngularJS', value: 'angular'}, {text: 'Backbone.js', value: 'backbone'}]
          })
          framework = 'None';
      }
  3. The metadata options declare
 export interface PropertyItemMeta {
    name: string; // The display name of the property in the grid
    description?: string; // A description of the property, will be used as tooltip on an hint element (a span with text "[?]")
    order?: number; // The display order.
    group?: string; //  The group this property belongs to
    hidden?: boolean | ((obj: unknown) => boolean); // Whether this property should be hidden in the grid, default is false (can be omitted).
    collapse?: boolean; // Whether the subItems should collapse. default is true
    type?: 'color' | 'date' | 'checkbox' | 'text' | 'options' | string | Type<ControlValueAccessor | ICustomDynamicComponent<any>>;
    // options: boolean number options label color,
    // or an custom component should be implement ControlValueAccessor or ICustomDynamicComponent<any>
    options?: any; // options for type
    colSpan2?: boolean; //  - true/false. If true then property input will span both columns and will have no name/label
    // (useful for textarea custom type)
    valueConvert?: (value: any) => any; // convert the value, eg. parseInt
    valueChanged?: (newValue: any, oldValue: any) => void; 
}

The metadata object

As seen from the example above the metadata object can be used (it's optional) in order to describe the object properties. Each proprty in the metadata object could have the following:

  • name - The display name of the property in the grid
  • description - A description of the property, will be used as tooltip on an hint element (a span with text "[?]")
  • hidden - Whether this property should be hidden in the grid, default is false (can be omitted).
  • group - The group this property belongs to
  • type - The type of the property, supported are:
    • boolean or checkbox - A checkbox would be used
    • number - simple textbox
    • color - simple textbox
    • options - A dropdown list would be used in case the metadata contains the options array property
    • label - A label will be used, useful for uneditable / read-only properties
  • colspan2 - true/false. If true then property input will span both columns and will have no name/label (useful for textarea custom type)

ngx-property-grid's People

Contributors

bors[bot] avatar jaspeling-rabo avatar mokeyish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ngx-property-grid's Issues

BrowserModule has already been loaded

ngx-property-grid is useful to my angular-cli project, but when I installed this module, I got a BrowserModule error. I think Your index.ts in the property-grid imports the BrowserAnimationsModule that should be remove.

Adding metadata to the decorator

Is your feature request related to a problem? Please describe.
I need to be able to handle additional properties on the templates - for instance read-only, or style changes.

Describe the solution you'd like
To have a properties property on the @meta({...}) decorator where you can pass any desired properties to your current property in the options. This will be able to be used in the template to override default behaviour.

Describe alternatives you've considered
Creating different templates for each different state, but that will mean that you will have to create multiple different components for small changes that could be done by binding to the @metadata@

Additional context
Something like this would be nice:
image

using it with xml

hello mokeyish,
Thank you for this code
I would like to use it with an xml - how can I do it?

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.