Step 1
First, we create an Angular project using Angular cli.
ng new demo --skip-tests --spec false
--skip-tests command is for removing test projects
--spec false command is for skip test file generation
Step 2
Now install smart table package in the project.
npm install ng2-smart-table --save
--save command is for adding external property.
Step 3
Add Ng2SmartTableModule reference in our app.module.ts
  1. import { Ng2SmartTableModule } from 'ng2-smart-table';
  2. @NgModule({
  3. imports: [
  4. Ng2SmartTableModule
  5. ],
  6. })
Step 4
We need to configure table and put ng2-smart-table component in app.component.html.
  1. <ng2-smart-table [settings]="settings" [source]="source"></ng2-smart-table>
Step 5
Add Setting Property inside component and create array for display data.
  1. public settings = {
  2. columns: {
  3. id: {
  4. title: 'Id',
  5. filter: true,
  6. },
  7. firstname: {
  8. title: 'Firstname',
  9. filter: true,
  10. },
  11. lastname: {
  12. title: 'Lastname',
  13. filter: true,
  14. }
  15. },
  16. pager: {
  17. display: true,
  18. perPage: 10
  19. },
  20. actions: {
  21. columnTitle: 'Action',
  22. add: false,
  23. edit: false,
  24. delete: false,
  25. position: 'left'
  26. },
  27. attr: {
  28. class: 'table table-striped table-bordered table-hover'
  29. },
  30. defaultStyle: false
  31. };
  32. data = [
  33. {
  34. id: 1,
  35. firstname: "Kaushik",
  36. lastname: "dhameliya"
  37. },
  38. {
  39. id: 2,
  40. firstname: "Manish",
  41. lastname: "Vadher"
  42. },
  43. {
  44. id: 3,
  45. firstname: "Sanket",
  46. lastname: "Vagadiya"
  47. },
  48. {
  49. id: 4,
  50. firstname: "Vaibhav",
  51. lastname: "Bavishi"
  52. },
  53. {
  54. id: 5,
  55. firstname: "Tushar",
  56. lastname: "Kyada"
  57. }];
Step 6
Run your application
ng serve -o
Source Code
Conclusion

Thanks a lot for reading. I hope you liked this article. Please share your suggestions and feedback.

3 Comments

Join the conversation! Your thoughts help the community grow.

  • Muthu Kumar

    How to add pageLimit option in ng2-smart-table

  • How to remove ng2-smart-table from website??

    • Remove ng2-smart-table in package.json, then fire npm install command after successfully run then remove all ng2-smart-table related variable in website