Angular4 Inline Editable Data Table: A reusable module which can be consumed like any other Angular modules. ===========================================
npm install angular-inline-editable-tablenpm install angular-inline-editable-table
import { EditableTableModule } from 'angular-inline-editable-table'
@NgModule( {
imports: [
EditableTableModule
]
} )
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
html
[columns]="['id','firstName','lastName','createdAt','updatedAt', 'Actions']"
[editableColumns] = "['lastName', 'createdAt', 'firstName']"
[dateColumns] ="['createdAt','updatedAt']"
[data]="tableData"
[pageSizeOptions]="[5,6,9,12,20,50,100]"
[searchable]="true"
(action)="action($event)"
[notification]="yourMessage"
[maxChar]="23">
``
* columns : Columns to be added to the table (see sample data below, make sure json keys matches the names of your columns in table)
* editableColumns : Columns which are editable (see sample data below, make sure json keys matches the names of your columns in table)
* data : Data to be displayed in table (see sample data below, make sure json keys matches the names of your columns in table)
* pageSizeOptions : Pagination options
* searchable : To add a search input to make the data searchable (default is false)
* action : A call back function which will be called after each actions like edit or delete
* notification : Add your custom message to be displayed as a notification after an action is performed on the table.
* maxChar : Maximum characters allowed in a column
interface tableData {
id:number,
firstName:string;
createdAt:Date;
updatedAt:Date;
}
const CUSTOMER_DATA: tableData[] = [
{id: 1, firstName: 'Ratnesh', updatedAt: new Date(), createdAt: new Date()},
{id: 2, firstName: 'Zing', updatedAt: new Date(), createdAt: new Date()},
{id: 3, firstName: 'Greg', updatedAt: new Date(), createdAt: new Date()},
{id: 4, firstName: 'Sana', updatedAt: new Date(), createdAt: new Date()},
{id: 5, firstName: 'Neha', updatedAt: new Date(), createdAt: new Date()},
{id: 6, firstName: 'Kiran', updatedAt: new Date(), createdAt: new Date()},
{id: 7, firstName: 'John', updatedAt: new Date(), createdAt: new Date()},
{id: 8, firstName: 'Engliue', updatedAt: new Date(), createdAt: new Date()},
{id: 9, firstName: 'Marina', updatedAt: new Date(), createdAt: new Date()},
{id: 10, firstName: 'Vivek', updatedAt: new Date(), createdAt: new Date()},
];
private dataLoaded: boolean;
private tableData: any
private yourMessage = []
tableData = CUSTOMER_DATA;
dataLoaded=true;
private action(row: any) {
if (row.operation === 'updated') {
this.update(row); // This is your update call to API
this.yourMessage.push('success','updated successfully') // Show update success notification
this.yourMessage = []; // make sure you empty it
}
if (row.operation === 'deleted') {
this.delete(row.id); // This is your delete call to API
this.yourMessage.push('success','deleted successfully') // Show delete success notification
this.yourMessage = []; // make sure you empty it
}
}
@import '~@angular/material/theming';
@import '~material-design-icons/iconfont/material-icons.css';
@import '~angular-notifier/styles.scss';
@include mat-core();
$primary: mat-palette($mat-light-blue);
$accent: mat-palette($mat-teal);
$theme: mat-light-theme($primary, $accent);
@include angular-material-theme($theme);
"styles": [
"src/styles.css",
"src/theming.scss"
],