mazdik / ng-mazdik

Angular UI component library
https://mazdik.github.io/ng-mazdik
MIT License
89 stars 34 forks source link

Save All for multiple rows changes #36

Closed hghew closed 5 years ago

hghew commented 5 years ago

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.

mazdik commented 5 years ago

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 5 years ago

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. =)