Skip to content

Commit

Permalink
feat: support column header in render
Browse files Browse the repository at this point in the history
  • Loading branch information
m2a2x committed Jul 23, 2024
1 parent bf3395b commit ce67ac3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
6 changes: 3 additions & 3 deletions projects/angular-datagrid/src/lib/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Handles the rendering and lifecycle of Angular components within StencilJS using updated Angular APIs.
*/
import { Injector, ComponentRef, Type, ApplicationRef, createComponent, EnvironmentInjector, inject } from '@angular/core';
import { ColumnDataSchemaModel } from '@revolist/revogrid';
import { ColumnDataSchemaModel, ColumnTemplateProp } from '@revolist/revogrid';

export interface AngularElement extends HTMLElement {
componentRef?: ComponentRef<any>; // Reference to the Angular component
Expand Down Expand Up @@ -73,12 +73,12 @@ export const Template = (
customProps?: any,
injector = inject(Injector)
) => {
return (h: any, p: ColumnDataSchemaModel, addition?: any) => {
return (h: any, p: ColumnDataSchemaModel | ColumnTemplateProp, addition?: any) => {
const props = customProps ? { ...customProps, ...p } : p;
props.addition = addition;
let lastEl: RenderedComponent<any> | null = null;
return h('span', {
key: `${p.prop}-${p.rowIndex}`,
key: `${p.prop}-${p.rowIndex || 0}`,
ref: (el: AngularElement | null) => {
lastEl = TemplateConstructor(el, AngularComponent, props, injector, lastEl);
}
Expand Down
27 changes: 21 additions & 6 deletions projects/demo-standalone/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import { Component } from '@angular/core';
import { type ColumnRegular, Editor, type Editors, RevoGrid, Template } from 'angular-datagrid';
import {
type ColumnRegular,
Editor,
type Editors,
RevoGrid,
Template,
} from 'angular-datagrid';
import { CellComponent } from './cell.component';
import { EditorComponent } from './editor.component';

@Component({
selector: 'app-root',
standalone: true,
imports: [RevoGrid, EditorComponent, CellComponent],
template: `<revo-grid style="height: 200px; width: 200px" [filter]="true" [columns]="columns" [source]="source" [editors]="editors"></revo-grid>`
template: `<revo-grid
style="height: 200px; width: 200px"
[filter]="true"
[columns]="columns"
[source]="source"
[editors]="editors"
></revo-grid>`,
})
export class AppComponent {
source: any[] = [ {
name: '1',
details: 'Item 1',
}];
source: any[] = [
{
name: '1',
details: 'Item 1',
},
];
columns: ColumnRegular[] = [];
editors: Editors = {};

Expand All @@ -34,6 +48,7 @@ export class AppComponent {
prop: 'name',
name: 'First',
editor: MY_EDITOR,
columnTemplate: Template(CellComponent),
cellTemplate: Template(CellComponent),
},
{
Expand Down
2 changes: 1 addition & 1 deletion projects/demo-standalone/src/app/cell.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export class CellComponent {
@Input() props!: ColumnDataSchemaModel;

get value() {
return this.props.rowIndex;
return this.props.prop;
}
}

0 comments on commit ce67ac3

Please sign in to comment.