I am using ng2-smart-table from https://akveo.github.io/ng2-smart-table/#/documentation
Live Demo: http://akveo.com/ngx-admin/pages/tables/smart-table
Please help me with below questions:
I want to select multiple rows and call one function so where I need to write this code in ng2-smart-table?
Can I select multiple rows and call one function on selected rows ?
I have written below code in .ts and .html files:
smart-table-component.ts:
actions: {
add: false,
edit: true,
delete: false,
custom: [{ name: 'ourCustomAction'}],
position: 'left',
columnTitle: 'Actions'
},
mode: 'external',
smart-table-component.html:
<nb-card-body>
<ng2-smart-table [settings]="settings" allowFiltering='true' allowPaging='true' [source]="windchillData"
(deleteConfirm)="onDeleteConfirm($event)" (custom)="onCustomAction($event)" (edit)="onEdit($event)">
</ng2-smart-table>
</nb-card-body>
1- I want to select multiple rows and call one function so where I need to write this code in ng2-smart-table?
Answer:
For selecting multiple rows in ng2-smart-table
, you need to add configuration in your settings
Object.
Example:
settings = {
// This `selectMode` is the configuration for selecting multiple rows in the table using checkbox
selectMode: 'multi',
delete: {
confirmDelete: true,
deleteButtonContent: 'Delete data',
saveButtonContent: 'save',
cancelButtonContent: 'cancel'
},
add: {
confirmCreate: true,
},
edit: {
confirmSave: true,
},
columns: {
// columns configuration
},
};
2- Can I select multiple rows and call one function on selected rows ?
ng2-smart-table
have an event to get userSelectedRows
, we can use that event to get all the selected rows and then call a function to do something with all selected rows.
Example:
<ng2-smart-table [settings]="settings" allowFiltering='true' allowPaging='true' [source]="windchillData" (deleteConfirm)="onDeleteConfirm($event)" (custom)="onCustomAction($event)" (edit)="onEdit($event)" (userRowSelect)="onUserRowSelect($event)"></ng2-smart-table>
component.ts
to get the selected rowsonUserRowSelect(event) {
this.selectedRows = event.selected;
}
Button in html
<button (click)="onClick()"> Get Selected </button>
Click handler in component.ts
onClick() {
// It will console all the selected rows
console.log(this.selectedRows);
}
Here you can see this in working: https://stackblitz.com/edit/example-ng2-smart-table-18qsws
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With