Skip to content

Commit

Permalink
feat(grid): add deleteDataGridItem & deleteDataGridItemById into Service
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Apr 13, 2018
1 parent bf83c90 commit 2e927f2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,48 @@ export class GridExtraService {
}

/**
* Update an existing item with new properties inside the datagrid
* Delete an existing item from the datagrid (dataView)
* @param object item: item object holding all properties of that row
*/
deleteDataGridItem(item: any) {
const row = this._dataView.getRowById(item.id);
const itemId = (!item || !item.hasOwnProperty('id')) ? -1 : item.id;

if (itemId === -1) {
throw new Error(`Could not find the item in the grid or it's associated "id"`);
}

// delete the item from the dataView
this._dataView.deleteItem(itemId);
this._dataView.refresh();
}

/**
* Delete an existing item from the datagrid (dataView)
* @param object item: item object holding all properties of that row
*/
deleteDataGridItemById(id: string | number) {
const row = this._dataView.getRowById(id);

if (!row) {
throw new Error(`Could not find the item in the grid by it's associated "id"`);
}

// delete the item from the dataView
this._dataView.deleteItem(id);
this._dataView.refresh();
}

/**
* Update an existing item with new properties inside the datagrid (dataView)
* @param object item: item object holding all properties of that row
*/
updateDataGridItem(item: any) {
const row = this._dataView.getRowById(item.id);
const itemId = (!item || !item.hasOwnProperty('id')) ? -1 : item.id;

if (itemId === -1) {
throw new Error(`Could not find the item in the item in the grid or it's associated "id"`);
throw new Error(`Could not find the item in the grid or it's associated "id"`);
}

const gridIdx = this._dataView.getIdxById(itemId);
Expand Down
3 changes: 1 addition & 2 deletions aurelia-slickgrid/src/examples/slickgrid/example3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ export class Example3 {
}
if (column.columnDef.id === 'delete') {
if (confirm('Are you sure?')) {
this.dataview.deleteItem(column.dataContext.id);
this.dataview.refresh();
this.gridExtraService.deleteDataGridItemById(column.dataContext.id);
}
}
});
Expand Down
3 changes: 1 addition & 2 deletions client-cli/src/examples/slickgrid/example3.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ export class Example3 {
}
if (column.columnDef.id === 'delete') {
if (confirm('Are you sure?')) {
this.dataview.deleteItem(column.dataContext.id);
this.dataview.refresh();
this.gridExtraService.deleteDataGridItemById(column.dataContext.id);
}
}
});
Expand Down
3 changes: 1 addition & 2 deletions doc/github-demo/src/examples/slickgrid/example3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ export class Example3 {
}
if (column.columnDef.id === 'delete') {
if (confirm('Are you sure?')) {
this.dataview.deleteItem(column.dataContext.id);
this.dataview.refresh();
this.gridExtraService.deleteDataGridItemById(column.dataContext.id);
}
}
});
Expand Down

0 comments on commit 2e927f2

Please sign in to comment.