You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.9KB

  1. window.employeeDirectory = function () {
  2. return {
  3. search: '',
  4. table: null,
  5. init() {
  6. this.search = this.$root.querySelector('#employee-search')?.value ?? '';
  7. this.initTable();
  8. document.body.addEventListener('employees-changed', () => {
  9. this.reloadTable();
  10. });
  11. },
  12. initTable() {
  13. const tableElement = document.getElementById('employee-table');
  14. if (!tableElement || typeof Tabulator === 'undefined') {
  15. return;
  16. }
  17. this.table = new Tabulator(tableElement, {
  18. ajaxURL: '/employees/data',
  19. ajaxParams: {
  20. search: this.search,
  21. },
  22. layout: 'fitColumns',
  23. responsiveLayout: 'collapse',
  24. pagination: true,
  25. paginationMode: 'local',
  26. paginationSize: 8,
  27. movableColumns: true,
  28. placeholder: 'No employees found.',
  29. columns: [
  30. { title: 'Name', field: 'full_name', minWidth: 180 },
  31. { title: 'Email', field: 'email', minWidth: 220 },
  32. { title: 'Department', field: 'department', minWidth: 140 },
  33. { title: 'Job Title', field: 'job_title', minWidth: 180 },
  34. { title: 'Start Date', field: 'start_date', hozAlign: 'left', minWidth: 130 },
  35. ],
  36. });
  37. },
  38. applySearch() {
  39. if (!this.table) {
  40. return;
  41. }
  42. this.table.setData('/employees/data', {
  43. search: this.search,
  44. });
  45. },
  46. reloadTable() {
  47. if (!this.table) {
  48. this.initTable();
  49. return;
  50. }
  51. this.table.setData('/employees/data', {
  52. search: this.search,
  53. });
  54. },
  55. };
  56. };

Powered by TurnKey Linux.