angular2-grid
angular2-grid copied to clipboard
Create an NgGrid Component
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...
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?
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?
Here is my grid component. https://github.com/lunzhang/ng2-grid
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.
Hello @BTMorton , Any Progress on this feature ?