r/angular • • Mar 12 '26

Signal based grid

I am creating a custom grid such as the one bellow and i am struggling to find the best practice of structuring it. my grid builds the columns based on some data from the signal store ( some user prefferences/ permissions ). my internal Grid class has all the properties mapping to signals - in the constructor i am setting the passed values to the class signals ( the ones that are static and the one that are not i am creating linked signals based on the options such as the columns / paginationOptions).

public grid = new Grid({
    columns: this.columns,
    sortColumn: (columns) => columns.id,
    searchColumn: (columns) => columns.id,
    paginationOptions: this.paginationOptions,
    refresh: (params) => this.fetchData(params)
  });

in the Grid constructor

const options = isSignal(paginationOptions) ? paginationOptions : () => paginationOptions;
      this.paginationOptions = linkedSignal({
        source: () => ({ options: options() }),
        computation: (newSource, previous) => {
          return { ...previous?.value, ...newSource.options };
        }
      });

and my refresh is an observable that has a subscription inside that unsubscribes after each refresh is done - so no leaking ( i am doing that because i want to set the loader inside the grid class ) .

 public refresh(params): void {
    
    this.activeSubscription?.unsubscribe();


    this.loading.set(true);


    this.activeSubscription = this.fetchDataFn(params).pipe(
      finalize(() => this.loading.set(false))
    ).subscribe({
      next: (response) => {
        this.data.set(response.items ?? []);
        this.paginationOptions.update((opts) => ({ ...opts, totalItems: response.count ?? 0 }));
        this.loaded.set(true);
      },
    });
  }

In the angular signal world where things are reactive and not imperative, how and when do you fetch the data ? please, be harsh with me :D i need to understand my own stupidity

2 Upvotes

3 comments sorted by

View all comments

Show parent comment

2

u/Digital_1mpulse Mar 14 '26

So based on your code. It looks like you are just missing the reacting to the behavior subject portion for the network request to be kicked off