ag-grid.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*=========================================================================================
  2. File Name: ag-grid.js
  3. Description: Aggrid Table
  4. --------------------------------------------------------------------------------------
  5. Item Name: Vuexy - Vuejs, HTML & Laravel Admin Dashboard Template
  6. Author: PIXINVENT
  7. Author URL: http://www.themeforest.net/user/pixinvent
  8. ==========================================================================================*/
  9. $(document).ready(function() {
  10. /*** COLUMN DEFINE ***/
  11. var columnDefs = [
  12. {
  13. headerName: "First Name",
  14. field: "firstname",
  15. editable: true,
  16. sortable: true,
  17. filter: true,
  18. width: 175,
  19. filter: true,
  20. checkboxSelection: true,
  21. headerCheckboxSelectionFilteredOnly: true,
  22. headerCheckboxSelection: true
  23. },
  24. {
  25. headerName: "Last Name",
  26. field: "lastname",
  27. editable: true,
  28. sortable: true,
  29. filter: true,
  30. width: 175
  31. },
  32. {
  33. headerName: "Company",
  34. field: "company",
  35. editable: true,
  36. sortable: true,
  37. filter: true,
  38. width: 250
  39. },
  40. {
  41. headerName: "City",
  42. field: "city",
  43. editable: true,
  44. sortable: true,
  45. filter: true,
  46. width: 125
  47. },
  48. {
  49. headerName: "Country",
  50. field: "country",
  51. editable: true,
  52. sortable: true,
  53. filter: true,
  54. width: 150
  55. },
  56. {
  57. headerName: "State",
  58. field: "state",
  59. editable: true,
  60. sortable: true,
  61. filter: true,
  62. width: 125
  63. },
  64. {
  65. headerName: "Zip",
  66. field: "zip",
  67. editable: true,
  68. sortable: true,
  69. filter: true,
  70. width: 125
  71. },
  72. {
  73. headerName: "Email",
  74. field: "email",
  75. editable: true,
  76. sortable: true,
  77. filter: true,
  78. width: 260,
  79. pinned: "left"
  80. },
  81. {
  82. headerName: "Followers",
  83. field: "followers",
  84. editable: true,
  85. sortable: true,
  86. filter: true,
  87. width: 150
  88. }
  89. ];
  90. /*** GRID OPTIONS ***/
  91. var gridOptions = {
  92. columnDefs: columnDefs,
  93. rowSelection: "multiple",
  94. floatingFilter: true,
  95. filter: true,
  96. pagination: true,
  97. paginationPageSize: 20,
  98. pivotPanelShow: "always",
  99. colResizeDefault: "shift",
  100. animateRows: true,
  101. resizable: true
  102. };
  103. /*** DEFINED TABLE VARIABLE ***/
  104. var gridTable = document.getElementById("myGrid");
  105. /*** GET TABLE DATA FROM URL ***/
  106. agGrid
  107. .simpleHttpRequest({ url: "data/ag-grid-data.json" })
  108. .then(function(data) {
  109. gridOptions.api.setRowData(data);
  110. });
  111. /*** FILTER TABLE ***/
  112. function updateSearchQuery(val) {
  113. gridOptions.api.setQuickFilter(val);
  114. }
  115. $(".ag-grid-filter").on("keyup", function() {
  116. updateSearchQuery($(this).val());
  117. });
  118. /*** CHANGE DATA PER PAGE ***/
  119. function changePageSize(value) {
  120. gridOptions.api.paginationSetPageSize(Number(value));
  121. }
  122. $(".sort-dropdown .dropdown-item").on("click", function() {
  123. var $this = $(this);
  124. changePageSize($this.text());
  125. $(".filter-btn").text("1 - " + $this.text() + " of 500");
  126. });
  127. /*** EXPORT AS CSV BTN ***/
  128. $(".ag-grid-export-btn").on("click", function(params) {
  129. gridOptions.api.exportDataAsCsv();
  130. });
  131. /*** INIT TABLE ***/
  132. new agGrid.Grid(gridTable, gridOptions);
  133. /*** SET OR REMOVE EMAIL AS PINNED DEPENDING ON DEVICE SIZE ***/
  134. if ($(window).width() < 768) {
  135. gridOptions.columnApi.setColumnPinned("email", null);
  136. } else {
  137. gridOptions.columnApi.setColumnPinned("email", "left");
  138. }
  139. $(window).on("resize", function() {
  140. if ($(window).width() < 768) {
  141. gridOptions.columnApi.setColumnPinned("email", null);
  142. } else {
  143. gridOptions.columnApi.setColumnPinned("email", "left");
  144. }
  145. });
  146. });