Guest User

Untitled

a guest
Dec 15th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. <table id="users-table" class="table table-hover table-condensed" style="width:100%">
  2. <thead>
  3. <tr>
  4. <th><input type="checkbox" id="master"></th>
  5. <th>Category</th>
  6. <th>Description</th>
  7. <th>Number of Items</th>
  8. <th>Action</th>
  9. </tr>
  10. </thead>
  11. </table>
  12.  
  13.  
  14. <script type="text/javascript">
  15. $(document).ready(function() {
  16.  
  17. oTable = $('#users-table').DataTable({
  18. "processing": true,
  19. "serverSide": true,
  20. "bProcessing":false,
  21. "bSort":false,
  22. "ajax": "{{ route('datatable.getcategories') }}",
  23. "columns": [
  24. {data: 'checkbox', name: 'checkbox', orderable: false, searchable: false},
  25. {data: 'name', name: 'name'},
  26. {data: 'action', name: 'action', orderable: false, searchable: false}
  27. ],
  28. });
  29. });
  30.  
  31. </script>
  32.  
  33. $stduents= Student::all();
  34. return Datatables::of($student)->addColumn('checkbox', function ($std) {
  35. return '<input type="checkbox" class="sub_chk" data-id="'.$std->id.'">';
  36. })->make(true);
  37.  
  38. $("i[type='icon']").css('display','none'); //set style explicitly
  39.  
  40. $('#master').on('click', function(e) {
  41. if($(this).is(':checked',true))
  42. {
  43. $(".sub_chk").prop('checked', true);
  44. } else {
  45. $(".sub_chk").prop('checked',false);
  46. }
  47. });
  48.  
  49.  
  50.  
  51. $('.delete_all').on('click', function(e) {
  52.  
  53. var allVals = [];
  54. $(".sub_chk:checked").each(function() {
  55. allVals.push($(this).attr('data-id'));
  56. });
  57.  
  58. if(allVals.length <=0)
  59. {
  60. alert("Please select row.");
  61. }
  62.  
  63. else {
  64.  
  65.  
  66.  
  67. var check = confirm("Are you sure you want to delete this row?");
  68. if(check == true){
  69.  
  70. var join_selected_values = allVals.join(",");
  71.  
  72. $.ajax({
  73. url: $(this).data('url'),
  74. type: 'GET',
  75. headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
  76. data: 'ids='+join_selected_values,
  77.  
  78. success: function (data) {
  79. if (data['success'])
  80. {
  81. $("#" + data['tr']).slideUp("slow");
  82. location.reload();
  83.  
  84. alert(data['success']);
  85. }
  86. else if (data['error'])
  87. {
  88. alert(data['error']);
  89. }
  90. else
  91. {
  92. //alert('Whoops Something went wrong!!');
  93. }
  94. },
  95. error: function (data) {
  96. alert(data.responseText);
  97. }
  98. });
  99.  
  100. $.each(allVals, function( index, value )
  101. {
  102. $('table tr').filter("[data-row-id='" + value + "']").remove();
  103. });
  104. }
  105. }
  106. });
  107.  
  108. $('[data-toggle=confirmation]').confirmation({
  109. rootSelector: '[data-toggle=confirmation]',
  110. onConfirm: function (event, element) {
  111. element.trigger('confirm');
  112. }
  113. });
  114.  
  115. $(document).on('confirm', function (e) {
  116. var ele = e.target;
  117. e.preventDefault();
  118.  
  119. $.ajax({
  120. url: ele.href,
  121. type: 'GET',
  122. headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
  123. success: function (data) {
  124. if (data['success'])
  125. {
  126. $("#" + data['tr']).slideUp("slow");
  127. location.reload();
  128.  
  129. alert(data['success']);
  130. }
  131. else if (data['error']) {
  132. alert(data['error']);
  133. }
  134. else
  135. {
  136. alert('Whoops Something went wrong!!');
  137. }
  138. },
  139. error: function (data) {
  140. alert(data.responseText);
  141. }
  142. });
  143.  
  144. return false;
  145. });
  146.  
  147.  
  148.  
  149. });
  150.  
  151. </script>
  152.  
  153. <script>
  154.  
  155. $("input[type='checkbox']").click(function() {
  156. var atLeastOneChecked = false;
  157. $("input[type='checkbox']").each(function(index) {
  158. if ($(this).prop('checked'))
  159. atLeastOneChecked = true;
  160. });
  161. if (atLeastOneChecked) {
  162. $("i[type='icon']").show(); //built-in jquery function
  163. //...or...
  164. $("i[type='icon']").css('display','inline-block'); //or set style explicitly
  165. } else {
  166. $("i[type='icon']").hide(); //built-in jquery function
  167. //...or...
  168. $("i[type='icon']").css('display','none'); //set style explicitly
  169. }
  170. });
  171. </script>
Add Comment
Please, Sign In to add comment