angular2-grid icon indicating copy to clipboard operation
angular2-grid copied to clipboard

Create an NgGrid Component

Open BTMorton opened this issue 9 years ago • 5 comments

There should be a component option as well as the directive currently provided. This should take the basic form of:

<ngGrid [items]="items"></ngGrid>

Things that need to be considered:

  • Event bindings/triggers
  • Serialisation #66
  • Custom item rendering
  • Probably more...

BTMorton avatar May 24 '16 09:05 BTMorton

From @tudorgergely https://github.com/BTMorton/angular2-grid/issues/80#issuecomment-221345908

So I played around to the component and ended up with a template like this (inside it):

   <div [ngGrid]="config">
       <div [ngGridItem]="item.config"
            *ngFor="let item of items; let i = index"
            id="gridItem_{{i}}">
       </div>
   </div>

and the template of a gridItem is given by another component (and added dynamically):

private addItems(items: any[]): void { items.forEach((item, index) => this.createItem(item.component, index)); }

private createItem(component, index) { this.cmpResolver.resolveComponent(component) .then((factory:ComponentFactory) => factory.create(this.viewContainer.injector, undefined, #gridItem_${index})) } This way we can specify the component and config of our item inside an object with this structure:

   {
       config: {
           col: 0,
           row: 12,
           sizex: 16,
           sizey: 2,
       },
       component: TestComponent,
   },

What do you think of this approach? it is working pretty well for me

Actually, I think it would be better to extend the NgGrid directive. That way for things that can only be controlled by the component itself (dragging in external items/dragging between grids) the new/extra code can be added explicitly to the component, rather than having to try doing various checks on the grid directive. Thoughts?

BTMorton avatar May 24 '16 19:05 BTMorton

I would not extend the NgGrid directive. What I would do is extract a lot of the things NgGrid does in separate services and reuse that.

Extending things is not really nice and good, I would favor composition (through services in this case) to extension everyday.

Don't you agree?

tudorgergely avatar Jun 18 '16 09:06 tudorgergely

Here is my grid component. https://github.com/lunzhang/ng2-grid

lunzhang avatar Dec 15 '16 17:12 lunzhang

I would like to see such a component. If you want to access some of the NgGrid functions there is no way to do it.

frankiDotNet avatar Jan 25 '17 12:01 frankiDotNet

Hello @BTMorton , Any Progress on this feature ?

Chintanvpatel avatar Jan 31 '17 13:01 Chintanvpatel