Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(angular-table): improve adapter implementation #5524

Conversation

riccardoperra
Copy link
Contributor

@riccardoperra riccardoperra commented May 3, 2024

A little summary about the latest PR that got merged (hope with a new branch name there are no issue 😥 )

  • Add support for required signal inputs (add ed an example too)
  • Basic example
  • Grouping example
  • Row selection example
  • Column visibility example

Examples to add:

  • Column ordering example
  • Column pinning example
  • Column pinning sticky example
  • Filters

With this PR i'm updating the flexRender implementation which has improved typings and now supports all types of renderable content (strings, components and templateRefs) directly through the columns header/cell definition.

The implementation seems a little clunky than other frameworks in order to avoid changeDetection issues and support the OnPush ChangeDetection in all components (i'm using the RowSelection example as a base).

@Component({
  template: `
    <input
      type="checkbox"
      [checked]="context.row.getIsSelected()"
      (change)="context.row.getToggleSelectedHandler()($event)"
    />
  `,
  host: {
    class: 'px-1 block',
  },
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TableRowSelectionComponent<T> {
  context = injectFlexRenderContext<CellContext<T, unknown>>()
}

@Component({
  template: `
       ...

      @for (cell of row.getVisibleCells(); track cell.id) {
        <td>
          <ng-container *flexRender="cell.column.columnDef.cell; props: cell.getContext(); let renderCell">
              {{renderCell}}
          </ng-container>
        </td>
     }
  `
})
class MyComponent { 
  private readonly otherCellRef = viewChild.required<TemplateRef<unknown>>('otherCellTemplateRef');

  readonly columns = [
    { 
       id: "select",
       cell: () => new FlexRenderComponent(TableRowSelectionComponent)
    },
    {
      id: "otherCell",
      cell: () => this.otherCellRef()
    }
  ]
}

As the example above, you can now define a new component for the header/cell. The component can access to the given props (e.g. CellContext or HeaderContext value) via *flexRender directive through the injectFlexRenderContext function.

Copy link

nx-cloud bot commented May 3, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 4c765c3. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@KevinVandy
Copy link
Member

Thanks for your continued work on this. And you can mark as ready to review at any point you think new changes can go into the feat branch in this repo.

@riccardoperra riccardoperra marked this pull request as ready for review May 4, 2024 14:27
@riccardoperra
Copy link
Contributor Author

@KevinVandy I've added the last examples that I was planning to add in this PR:

  • Column ordering
  • Column pinning
  • Column pinning
  • Filters

I think all changes are ready to be merged into the feat branch 😄

@KevinVandy KevinVandy merged commit d4c514a into TanStack:feat-angular-table May 4, 2024
2 checks passed
@riccardoperra riccardoperra deleted the feat/angular-table-impl-and-examples branch May 4, 2024 14:39
merto20 added a commit to merto20/angular-table that referenced this pull request May 5, 2024
* Added optional injector for more flexibility
* Replace runInInjectionContext with injector in effect
KevinVandy pushed a commit that referenced this pull request May 7, 2024
…bility (#5525)

* feat(angular-table): improve adapter implementation (#5524)

* Added optional injector for more flexibility
* Replace runInInjectionContext with injector in effect

* feat(angular-table): Added proxifyTable back

* feat(angular-table): adding back notifier signal for table changed

* feat(angular-table): Improve logic in setting table options
*set table options inside computed before returning the table instance
*remove redundant signals and effect
*remove injector as it no longer required
*update Grouping example to show how to pass signal when creating table
KevinVandy added a commit that referenced this pull request May 12, 2024
* feat(angular-table): adds Angular adapter for tanstack/table (#5326)

* Angular adapter for tanstack table initial

* build with: ng packagr

* Add angular examples basic grouping

* Add angular examples basic grouping

* Update angular examples basic grouping

* Add angular example selection

* regen lock file

* package upgrades, angular table docs

* prettier

* move around some deps

* removed unused dependency from angular package

* fix deps

---------

Co-authored-by: Kevin Van Cott <kevinvandy656@gmail.com>

* docs config cleanup

* feat: signal angular table adapter implementation

* update demo

* feat: table proxy detect memoized fns

* fix proxy property returning value

* feat: improve naming

* save new reference of table signal on every update

* computed trap proxy for fns with 1 argument

* update pnpm-lock.yaml

* refactor proxy implementation

* fix dependencies

* cleanup imports

* refactor basic example

* fix build

* run prettier

* add grouping example, fix ci

* add grouping example, fix ci

* add row selection example

* add column visibility example

* update examples add signal input required example

* improve angular table impl, fix flex-render change detection issues

* fix build

* feat(angular-table): improve adapter implementation (#5524)

* feat(angular-table): support render dynamic components and templateRefs in table

* update row selection example using dynamic rendered components

* support change detection on push with flex render

* add column ordering example

* fix flexRender change detection issues

* rename properties

* fix prettier and adjust example budget options

* update basic example

* add again support for table signal

* add column-pinning example

* add column pinning example

* add filters example

* cleanup code

* example cleanup

* update lock file

* feat(angular-table): added injector optional parameter for more flexibility (#5525)

* feat(angular-table): improve adapter implementation (#5524)

* Added optional injector for more flexibility
* Replace runInInjectionContext with injector in effect

* feat(angular-table): Added proxifyTable back

* feat(angular-table): adding back notifier signal for table changed

* feat(angular-table): Improve logic in setting table options
*set table options inside computed before returning the table instance
*remove redundant signals and effect
*remove injector as it no longer required
*update Grouping example to show how to pass signal when creating table

* update angular adapter and state docs

* prettier

* update docs config with angular examples

* update angular table state docs (#5545)

* Angular examples and dependencies improvements (#5546)

* tslib should be a dependency, see:

https://angular.io/guide/angular-package-format#tslib

* ensure angular examples are run as web container on code sandbox

* update lock file

---------

Co-authored-by: Kevin Vandy <kevinvandy656@gmail.com>

* docs(angular-table): Add documentation for FlexRenderDirective (#5543)

* add flexRender documentation

* fix docs

* fix rendering component section heading

* remove double build package.json from angular build

* update link name

* docs pass

* update esm exports in package.json

* update flexrender types

---------

Co-authored-by: jrgokavalsa <86955546+jrgokavalsa@users.noreply.github.com>
Co-authored-by: riccardoperra <riccardo.perra@icloud.com>
Co-authored-by: Riccardo Perra <perrariccardo0@gmail.com>
Co-authored-by: mamerto-g <merto.20@gmail.com>
Co-authored-by: Arnoud <6420061+arnoud-dv@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants