Advertisement
fadlyshafa

Untitled

Sep 16th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.41 KB | None | 0 0
  1. @extends('admin.layouts.master')
  2.  
  3. @section('content')
  4.  
  5. <link rel="stylesheet" href="https://datatables.yajrabox.com/highlight/styles/zenburn.css">
  6. <script src="https://datatables.yajrabox.com/highlight/highlight.pack.js"></script>
  7.  
  8. <div class="row">
  9.     <div class="col-md-12">
  10.         <h4>{{ $title }}</h4>
  11.         <div class="box box-warning">
  12.             <div class="box-header">
  13.                 <p>
  14.                     <button class="btn btn-flat btn-sm btn-warning btn-refresh"><i class="fa fa-refresh"></i> Refresh</button>
  15.                 </p>
  16.             </div>
  17.             <div class="box-body">
  18.                 <table class="table table-hover tbl-absen">
  19.                     <thead>
  20.                         <tr>
  21.                             <th></th>
  22.                             <th>#</th>
  23.                             <th>Nama</th>
  24.                             <th>total_masuk</th>
  25.                             <th>total_pulang</th>
  26.                         </tr>
  27.                     </thead>
  28.                 </table>
  29.             </div>
  30.         </div>
  31.     </div>
  32. </div>
  33.  
  34. @endsection
  35.  
  36. @section('scripts')
  37.  
  38. <script src="https://datatables.yajrabox.com/js/handlebars.js"></script>
  39.  
  40. <script id="details-template" type="text/x-handlebars-template">
  41.     <table class="table table-hover" id="@{{nik}}">
  42.         <thead>
  43.             <tr>
  44.                 <th>#</th>
  45.                 <th>Tanggal</th>
  46.                 <th>Absen Masuk</th>
  47.                 <th>Absen Pulang</th>
  48.             </tr>
  49.         </thead>
  50.     </table>
  51. </script>
  52.  
  53. <script type="text/javascript">
  54.     $(document).ready(function(){
  55.  
  56.  
  57.  
  58.         $('.btn-refresh').click(function(e){
  59.             e.preventDefault();
  60.             $('.preloader').fadeIn();
  61.             location.reload();
  62.         })
  63.  
  64.         var template = Handlebars.compile($("#details-template").html());
  65.  
  66.         var table = $('.tbl-absen').DataTable({
  67.             scrollY:400,
  68.             processing: true,
  69.             serverSide: true,
  70.             ajax: "{{ $yajra }}",
  71.             columns: [
  72.             // or just disable search since it's not really searchable. just add searchable:false
  73.                 {
  74.                     "className":      'details-control',
  75.                     "orderable":      false,
  76.                     "searchable":     false,
  77.                     "data":           null,
  78.                     "defaultContent": '<button class="btn btn-success btn-xs" id="delete"><i class="fa fa-plus"></i></button>'
  79.                 },
  80.                 {data: 'rownum', name: 'rownum'},
  81.                 {data: 'nama', name: 'nama'},
  82.                 {data: 'total_masuk', name: 'total_masuk'},
  83.                 {data: 'total_pulang', name: 'total_pulang'}
  84.             ]
  85.         });
  86.  
  87.         // Add event listener for opening and closing details
  88.         $('.tbl-absen tbody').on('click', 'td.details-control', function () {
  89.             var tr = $(this).closest('tr');
  90.             var row = table.row( tr );
  91.             var tableId = row.data().nik;
  92.  
  93.             if ( row.child.isShown() ) {
  94.                 // This row is already open - close it
  95.                 row.child.hide();
  96.                 tr.removeClass('shown');
  97.             }
  98.             else {
  99.                 // Open this row
  100.                 row.child(template(row.data())).show();
  101.                 initTable(tableId, row.data());
  102.                 tr.addClass('shown');
  103.                 tr.next().find('td').addClass('no-padding bg-gray');
  104.             }
  105.         });
  106.  
  107.         function initTable(tableId, data) {
  108.             $('#' + tableId).DataTable({
  109.                 scrollY:100,
  110.                 processing: true,
  111.                 serverSide: true,
  112.                 ajax: data.details_url,
  113.                 columns: [
  114.                 { data: 'rownum', name: 'rownum' },
  115.                 { data: 'tanggal', name: 'tanggal' },
  116.                 { data: 'masuk', name: 'masuk' },
  117.                 { data: 'pulang', name: 'pulang' },
  118.                 ]
  119.             })
  120.         }
  121.  
  122.     })
  123. </script>
  124.  
  125.  
  126.  
  127. @endsection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement