<!-- Page Heading -->


          <!-- <h1 class="h3 mb-2 text-gray-800">Tables</h1>


          <p class="mb-4">DataTables is a third party plugin that is used to generate the demo table below. For more information about DataTables, please visit the <a target="_blank" href="https://datatables.net">official DataTables documentation</a>.</p> -->





          <!-- DataTales Example -->





  





          <div class="card shadow mb-4">


            <div class="card-header py-3">


              <h6 class="m-0 font-weight-bold text-primary">Data Strategi</h6>


            </div>


            <div class="card-body">


              <!-- <a href='javascript:void(0)' onclick="getpopup('popup/tambah_head_strategi','popupedit');" class="btn btn-primary btn-icon-split btn-sm mb-4">


                    <span class="icon text-white-50">


                      <i class="fas fa-plus"></i>


                    </span>


                    <span class="text">Tambah Head Strategi</span>


              </a> -->


              <div class="table-responsive">


                <table class="table table-bordered" id="tabel_data_pka" width="100%" cellspacing="0">


                  <thead>


                    <tr>


                      <th>No</th>


                      <th>Nama Head</th>


                      <th>Nomor Head</th>


                      <th>Jumlah Sub Strategi</th>


                      <!-- <th>Aksi</th> -->


                    </tr>


                  </thead>


                  <!-- <tfoot>


                    <tr>


                      <th>Name</th>


                      <th>Position</th>


                      <th>Office</th>


                      <th>Age</th>


                      <th>Start date</th>


                      <th>Salary</th>


                    </tr>


                  </tfoot> -->


                  <tbody>


                  </tbody>


                </table>


              </div>


            </div>


          </div>


<script type="text/javascript">


$(document).ready(function(){


    


    var base_url = "<?=base_url()?>";


    


    var data_pka = function(){


        $('#tabel_produk').hide();


        $.ajax({ 


            url: base_url + 'strategi/data_head_strategi',


            type: "post",


            // data:{<?php echo $this->security->get_csrf_token_name(); ?>:'<?php echo $this->security->get_csrf_hash(); ?>'},


            // data:{},


            dataType: "json",


            async : 'false',


            success: function(result){


              // alert(JSON.stringify(result))


              var data = [];


                for ( var i=0 ; i<result.length ; i++ ) {


                  // alert(result[i].kode_pka)


                    var no = i+1;


                    var link_tambah = `<a href="javascript:void(0)" onclick="getpopup('Popup/tambah_nomor_strategi','popupedit','`+result[i].kode_head+`','`+result[i].head+`');" class="btn btn-success btn-icon-split btn-sm" title="Tambah Nomor Strategi">


                                        <span class="icon text-white-50">


                                          <i class="fas fa-plus"></i>


                                        </span>


                                      </a>`;


                    var link_detail = `<a href="javascript:void(0)" onclick="getpopup('Popup/detail_nomor_strategi','popupedit','`+result[i].kode_head+`','`+result[i].head+`');" class="btn btn-primary btn-icon-split btn-sm" title="Detail Nomor Strategi">


                                        <span class="icon text-white-50">


                                          <i class="fas fa-eye"></i>


                                        </span>


                                      </a>`;


                    var link_hapus = `<a href="javascript:void(0)" onclick="hapus_head_strategi('`+result[i].kode_head+`','`+result[i].head+`');"  class="btn btn-danger btn-icon-split btn-sm" title="Hapus Header Strategi">


                                        <span class="icon text-white-50">


                                          <i class="fas fa-trash-alt"></i>


                                        </span>


                                      </a>`;





                    data.push([no,result[i].head,result[i].kode_head,result[i].jml+" Strategi"/*,link_detail+" "+link_tambah+" "+link_hapus*/]);


                }


                $('#tabel_data_pka').DataTable({


                    //"bJQueryUI"     : true,


                    data                : data,


                    deferRender         : true,


                    processing          : true,


                    ordering            : true,


                    retrieve            : false,


                    paging              : true,


                    deferLoading        : 57,


                    bDestroy            : true,


                    autoWidth           : false,


                    bFilter             : true,


                    iDisplayLength      : 10,


                    responsive: true,


                    language: {


                      searchPlaceholder: 'Cari',


                      sSearch: '',


                      lengthMenu: '_MENU_',


                    },


                });


               


            },


            beforeSend: function () {





            },


            complete: function () {


                // $('#tabel_produk').show();


            }


        });


    }


    data_pka();


    hapus_head_strategi = function(kode_head,head){


      bootbox.confirm("Apakah Anda Yakin Akan Menghapus Data?", function(result){ 


        if (result==true) {


          $.ajax({


                url             : base_url + 'strategi/hapus_head_strategi', 


                type            : "POST",


                dataType        : 'json',


                data            : {kode_head:kode_head},


                success         : function(response){


                  if(response == true){


                        Command: toastr["success"]("Unit Misioner Berhasil Dihapus", "Berhasil");


                        getcontens('page/data_strategi');


                    }else{


                        Command: toastr["error"]("Simpan error, data tidak berhasil disimpan", "Error");


                    }


                },


                error: function(jqXHR, textStatus, errorThrown) {


                  $('#loading').modal('hide');


                  Command: toastr["error"](errorThrown, "Error");


                },


                beforeSend: function () {


                  $('#loading').modal('show');


                },


                complete: function () {


                    $('#loading').modal('hide');


                }


          })


        }


      });


    }


  });


</script>


