angular-2-data-table icon indicating copy to clipboard operation
angular-2-data-table copied to clipboard

Delete item (lines) according to checkbox value

Open Jureyder opened this issue 7 years ago • 1 comments

Hi there,

I can't reach what I expected to do, I would like to delete multiple item, multiple lines from a table, according to a checkbox value in this same table.

I actually want to check every line I want to delete, then erase them all by clicking on a button. The erase function was not a problem for one item, but I don't know how to detect a "Check" / "Uncheck" event in the checkbox. It is supposed to send the index of the item to a service that will add it to an Array.

How can I detect that a checkbox is checked/unchecked, to execute that kind of function?

Here is my declaration of the table from the HTML document : <data-table id="asset-grid" headerTitle="Assets" [items]="assets" [itemCount]="assetCount" (reload)="reloadAssets($event)" [autoReload]="true" [showReloading]="false" [selectColumn]="true" [multiSelect]="true" [indexColumn]="false">

Jureyder avatar Aug 07 '17 07:08 Jureyder

Hi,

You can use a @ViewChild(DataTable) assetsTable: DataTable; of your table and then in the TS file do a : this.assetsTable.selectedRows.forEach(aRow => this.assetService.assets.splice(aRow, 1) );

But the thing is that you have to sort your table, in order to delete the last one first, or you'll have an issue..

BayardSmart avatar Sep 18 '17 14:09 BayardSmart