Advertisement
aayushdahal

Untitled

Dec 14th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. var ColumnDefs = [
  2. { headerName: 'Id', field: 'restaurantId', width: 80 },
  3. { headerName: 'Restaurant Name', field: 'restaurantName', width: 235 },
  4. { headerName: 'Address', field: 'address', width: 150 },
  5. { headerName: 'Contact No', field: 'contactNo', width: 120 },
  6. {
  7. headerName: 'Active', field: 'isActive', width: 80,
  8. cellRenderer: (data) => {
  9. return data.value ? '<i class="fas fa-check text-success"></i>' : '<i class="fas fa-times text-danger"></i>';
  10. }
  11. },
  12. { headerName: 'Email', field: 'email', width: 150 },
  13. {
  14. headerName: 'Start Date', field: 'startDate', width: 100,
  15. cellRenderer: (data) => {
  16. return data.value ? (new Date(data.value)).toLocaleDateString() : '';
  17. }
  18. },
  19. {
  20. headerName: 'End Date', field: 'endDate', width: 100,
  21. cellRenderer: (data) => {
  22. return data.value ? (new Date(data.value)).toLocaleDateString() : '';
  23. }
  24. },
  25. {
  26. headerName: 'Edit', width: 80,
  27. cellRenderer: editButton,
  28. onCellClicked(params) {
  29. console.log(params.data);
  30. Edit(params.data);
  31. }
  32. }
  33. ];
  34.  
  35. var SplitDateTime = function (data) {
  36. var splitDateTime = data.split("T");
  37. var date = splitDateTime[0];
  38. return date;
  39. };
  40.  
  41. function Edit(data) {
  42. $('#id').val(data.id);
  43. $('#restaurantId').val(data.restaurantId);
  44. $('#restaurantName').val(data.restaurantName);
  45. $('#address').val(data.address);
  46. $('#contactNo').val(data.contactNo);
  47. $('#isActive').prop('checked', data.isActive ? true : false);
  48. $('#startDate').val(SplitDateTime(data.startDate));
  49. $('#email').val(data.email);
  50. $('#endDate').val(SplitDateTime(data.endDate));
  51. $('#createRestaurantModal').modal('toggle');
  52. }
  53.  
  54. var Clear = function () {
  55. $('#id').val('');
  56. $('#restaurantId').val('');
  57. $('#restaurantName').val('');
  58. $('#address').val('');
  59. $('#contactNo').val('');
  60. $('#isActive').prop('checked', false);
  61. $('#startDate').val('');
  62. $('#email').val('');
  63. $('#endDate').val('');
  64. };
  65.  
  66. function editButton() {
  67. return '<i class="btn fas fa-edit" id="editButton"></i>';
  68. }
  69.  
  70. var gridOptions = {
  71. columnDefs: ColumnDefs,
  72. rowHeight: 40,
  73. enableSorting: true,
  74. enableFilter: true,
  75. paginationAutoPageSize: true,
  76. pagination: true
  77. };
  78. function Save() {
  79. var record = {
  80. Id: $('#id').val(),
  81. RestaurantId: $('#restaurantId').val(),
  82. RestaurantName: $('#restaurantName').val(),
  83. Address: $('#address').val(),
  84. ContactNo: $('#contactNo').val(),
  85. IsActive: $('#isActive').prop('checked'),
  86. Email: $('#email').val(),
  87. StartDate: $('#startDate').val(),
  88. EndDate: $('#endDate').val()
  89. };
  90.  
  91. $('#restaurantInfoForm').one('submit', function (e) {
  92. e.preventDefault();
  93. e.stopPropagation();
  94. $.ajax({
  95. url: 'RestaurantInfo/Save',
  96. data: { record: record },
  97. method: 'POST',
  98. success: function () {
  99. console.log("Added Successfully");
  100. $('#createRestaurantModal').modal('toggle');
  101. getGridData();
  102. }
  103. });
  104. });
  105. }
  106.  
  107. var getGridData = function () {
  108. $.ajax({
  109. url: 'RestaurantInfo/GetRestaurantInfo',
  110. method: 'GET',
  111. success: function (data) {
  112. gridOptions.api.setRowData(data);
  113. console.log(data);
  114. }
  115. });
  116. };
  117.  
  118. $(document).ready(function () {
  119. var eGridDiv = document.querySelector('#myGrid');
  120.  
  121. new agGrid.Grid(eGridDiv, gridOptions);
  122.  
  123. getGridData();
  124.  
  125. $('#createBtn').click(function () {
  126. console.log('Button Pressed');
  127. Clear();
  128. });
  129.  
  130. $('#btnSave').on('click', function () {
  131. console.log($('#restaurantInfoForm')[0].reportValidity());
  132. if ($('#restaurantInfoForm')[0].reportValidity()) {
  133. Save();
  134. }
  135. });
  136. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement