list.pt 5.33 KB
<html metal:use-macro="load: ../base.pt">

<div metal:fill-slot="content">
  <link href="/static/datatables/extensions/TableTools/css/dataTables.tableTools.min.css" rel="stylesheet">
  <link href="/static/datatables/media/css/dataTables.bootstrap.css" rel="stylesheet">

<h4>Peruntukan BBM</h4>
<hr>
<table id="table1" name="table1" class="table table-bordered table-hover table-condensed" >
    <thead>
        <tr>
            <th>ID</th>
            <th>Kode</th>
            <th>Nama</th>
            <th>Status</th>            
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

<script src="/static/datatables/media/js/jquery.dataTables.min.js"></script>
<!--script src="/static/datatables/media/js/jquery.jeditable.js')}"></script-->
<script src="/static/datatables/media/js/jquery.dataTables.ext.js"></script>
<script src="/static/datatables/extensions/TableTools/media/js/ZeroClipboard.js"></script>
<script src="/static/datatables/media/js/dataTables.bootstrap.js"></script>

<script>
  var mID;
  var oTable;
  var iPos;
  var oFormUrl  = "/sptpd/peruntukan/";
  var oTableUrl = oFormUrl+"grid/act";
  $(document).ready(function () {
      oTable = $('#table1').dataTable({
          "sAjaxSource"     : oTableUrl,
          "bStateSave"      : true,
          "bServerSide"     : true,
          "bProcessing"     : true,
          "sDom"            : '<"toolbar">lfrtip',
          "bScrollCollapse" : true,
          "bSort"           : true,
          "bInfo"           : false,
          "bFilter"         : true,
          "bAutoWidth"      : false,
          "bPaginate"       : true,
          "sPaginationType" : "full_numbers",
          "lengthMenu": [
              [10, 25, 50, 100],
              [10, 25, 50, 100]
          ],
          "aoColumnDefs": [
              {
                  "bSearchable": false, 
                  "bVisible"   : false, 
                  "aTargets"   : [0]
              },{
                  "aTargets"   : [3], // Kolom Status
                  "mRender"    : function (data, type, full) {
                      if (data == "0") {
                          return 'Inaktif';
                      } else if (data == "1") {
                          return 'Aktif';
                      }
                  }
              }
          ],

          "aoColumns": [
              null, 
              {"sWidth": "120px"},
              null, 
              {"sWidth": "50px", "sClass": "center"},
              
          ],
            "language": {
                "search"  : "Cari: ",
                "paginate":{
                    "first"   : "Pertama ",
                    "last"    : "Terakhir ",
                    "previous": "Sebelumnya ",
                    "next"    : "Selanjutnya ",
                },
                "lengthMenu"  : "Tampil _MENU_ baris "
            }
      });

      var tb_array = [
          '<div class="btn-group pull-left">',
          '	<button id="btn_tambah" class="btn btn btn-primary pull-left" type="button">Tambah</button>',
          '	<button id="btn_edit" class="btn btn btn-primary pull-left" type="button">Edit</button>',
          '	<button id="btn_delete" class="btn btn btn-danger pull-left" type="button">Hapus</button>',
          //'	<button id="btn_print" class="btn btn btn-primary pull-left" type="button">Cetak</button>',
          '	<button id="btn_pdf" class="btn btn btn-success pull-left" type="button">PDF</button>',
          '	<button id="btn_csv" class="btn btn btn-info pull-left" type="button">CSV</button>',
          '	<button id="btn_close" class="btn btn btn-warning" type="button">Tutup</button>',
          '	&nbsp;',
          '</div>',
      ];

      var tb = tb_array.join(' ');
      $("div.toolbar").html(tb);

      $('#table1 tbody').on('click', 'tr', function () {
          if ($(this).hasClass('selected')) {
              mID = '';
              $(this).removeClass('selected');
          } else {
              iPos = oTable.fnGetPosition(this);
              var aData = oTable.fnGetData(iPos);
              mID = aData[0];
              oTable.$('tr.selected').removeClass('selected');
              $(this).addClass('selected');
          }
      });

      $('#btn_tambah').click(function () {
          window.location = oFormUrl+'add';
      });

      $('#btn_edit').click(function () {
          if (mID) {
              window.location = oFormUrl+mID+'/edit';
          } else {
              alert('Silahkan pilih data yang akan diedit');
          }
      });
      $('#btn_print').click(function () {
        url = '/sptpd/report/act/peruntukan?peruntukan_id='+mID
        if(mID) window.open(url);
        else window.open('/sptpd/report/act/semua_peruntukan');
            
      });

      $('#btn_pdf').click(function () {
          url = oFormUrl+"reg/pdf";
          window.open(url);
      });
      
      $('#btn_csv').click(function () {
          url = oFormUrl+"reg/csv";
          window.open(url);
      });

      $('#btn_close').click(function () {
          window.location = "/"
      });

      $('#btn_delete').click(function () {
          if (mID) {
              var hapus = confirm('Hapus data ini?');
              if (hapus == true) {
                  window.location = oFormUrl+mID+'/delete';
              };
          } else {
              alert('Silahkan pilih data yang akan dihapus');
          }
      });
  });
</script>

</div>

</html>