mazdik/ng-mazdik

Save All for multiple rows changes

hghew opened this issue · 2 comments

hghew commented

I am using the crud table from basic-demo, is there a way I can get all changes made to multiples rows, and I can customize my own Save All button to trigger save at once?

After the user changing multiple different rows/columns, it would be nice if they decide to Save All at once.

Your help is very much appreciated. Thanks.

Collect the modified lines, then save using the custom function

  private subscriptions: Subscription[] = [];
  private changedRows = new Set<Row>();

  ngOnInit() {
    const subCell = this.dataManager.events.cellSource$.subscribe((data) => {
      if (data.type === CellEventType.ValueChanged) {
        const row = this.dataManager.rows[data.rowIndex];
        if (!this.changedRows.has(row)) {
          if (this.dataManager.rowChanged(row)) {
            this.changedRows.add(row);
          }
        } else {
          if (!this.dataManager.rowChanged(row)) {
            this.changedRows.delete(row);
          }
        }
      }
    });
    this.subscriptions.push(subCell);
  }

  ngOnDestroy() {
    this.subscriptions.forEach(s => s.unsubscribe());
  }
hghew commented

it works with your code changes above, appreciates your help, thanks alot.

I added a piece of code to remove the changed row when call Revert Changes from the action menu. =)