This is a migrated thread and some comments may be shown as answers.

Grid - accessing a stream of data changed events.

2 Answers 494 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 06 Dec 2017, 10:17 AM

I've been using the InCellEditing and GridBinding directives with the KendoGrid in the way shown in your InCellEditing Example (https://www.telerik.com/kendo-angular-ui/components/grid/editing/editing-directives/#toc-the-in-cell-directive)

What I've needed to do recently is (ideally) subscribe to an Observable that would give me give me all the current data in the grid every time some data has been changed (added/updated/removed).

I went digging through the grid code base and saw that the Grid & InCellEditingDirective is injected with a LocalDataChangesService. I'd love to be able to access this service too so that I can consume a stream of change events.

Is there an easy way to achieve this?

2 Answers, 1 is accepted

Sort by
0
Simon
Top achievements
Rank 1
answered on 06 Dec 2017, 10:36 AM

My best effort so far (continuing to use the InCellEditingDirective example) has been this...

 

@ViewChild(GridComponent)
private grid: GridComponent;
 
ngOnInit() {
    // subscibe to the grid's cell-close, save & remove events for saving items
    this.grid
        .save
        .merge(this.grid.cellClose)
        .merge(this.grid.remove)
        .pipe(
            this.combineSaveEventAndCurrentProducts(),
            debounceTime(3000),
            distinctUntilChanged()
        )
        .subscribe(p => this.saveToApi(p));
}
 
private combineRowEventAndCurrentAddressBook = () => map((e: SaveEvent|CellCloseEvent|RemoveEvent) => {
    const productSnapshot = [...this.products];
 
    if (e && e.hasOwnProperty('formGroup')) {
        // save event raised, new row added.
        productSnapshot.push(e.dataItem);
    }
 
    return productSnapshot;
})
 
private saveToApi(products: any[]) {
    // api persist code...
    // this api can only persist all the products in one great lump
}
0
Svet
Telerik team
answered on 08 Dec 2017, 07:24 AM
Hi Simon,

The demonstrated approach of subscribing to all data change events of the Grid is valid.

However, accessing the LocalDataChangesService is not allowed as it is used only for internal data operations.

Please let us know in case you need further assistance for the built-in functionality of the Grid.

Regards,
Svetlin
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
Simon
Top achievements
Rank 1
Answers by
Simon
Top achievements
Rank 1
Svet
Telerik team
Share this question
or