<div class="content-wrapper">
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="m-0">Statistik Distribusi - Kabupaten</h1>
                </div><!-- /.col -->
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="<?=base_url()?>/home">Home</a></li>
                    <li class="breadcrumb-item active">Statistik Distribusi Kabupaten</li>
                    </ol>
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.container-fluid -->
    </div>
    <hr/>
    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <div class="card card-outline card-primary">
                        <div class="card-header">
                            <div class="card-title">
                                Data Distribusi
                            </div>
                            <div class="card-tools">
                                <a href="<?=base_url()?>users_admin_add" class="btn btn-sm btn-primary">Tambah Admin Baru</a>
                            </div>
                        </div>
                        <div class="card-body">
                            <table id="tbl_data1" class="table table-striped table-bordered display compact nowrap" style="width:100%">
                                <thead>
                                    <tr>
                                        <th class="sb-filter">Kode Provinsi</th>
                                        <th class="sb-filter">Nama Provinsi</th>
                                        <th class="sb-filter">Kode Kabupaten</th>
                                        <th class="sb-filter">Nama Kabupaten</th>
                                        <th class="sb-filter">Jumlah Kecamatan</th>
                                        <th class="sb-filter">Jumlah Kelurahan</th>
                                        <th class="sb-filter">Jumlah Penduduk</th>
                                        <th class="sb-filter">Jumlah Pangkalan</th>
                                        <th class="sb-filter">Jumlah Pendistribusian</th>
                                        <th class="sb-filter">Rata - Rata Kebutuhan</th>
                                        <th class="sb-filter">Index Konsumsi</th>
                                        <th class="sb-filter">Kebutuhan Alokasi</th>
                                        <th class="sb-filter">Plus Minus</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    foreach($stat_kabupaten as $item):
                                    ?>
                                    <?php
                                    endforeach;
                                    ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            
        </div>
        <style>
            .dataTables_wrapper .dataTables_filter{
                float:left !important;
            }
        </style>
        <script type="text/javascript">
            $(document).ready(function () {
                <?php
                if (isset($error))
                {
                    ?>
                    $(document).Toasts('create', {
                        class: 'bg-danger',
                        title: 'Error',
                        subtitle: 'Terjadi Kesalahan',
                        body: '<?=$error?>'
                    })
                    <?php
                }
                ?>
                var table1 = $("#tbl_data1").DataTable({
                    processing: true,
                    serverSide: true,
                    scrollX: true,
                    pageLength:25,
                    searchDelay: 1500,
                    order: [[2, 'asc']],
                    dom: "<'row mb-3'<'col-sm-12'Q>>" +
                    "<'row mb-3'<'col-sm-12'B>>" +
                    "<'row mb-2'<'col-sm-6'f><'col-sm-6'p>>" +
                    "<'row'<'col-sm-12'tr>>" +
                    "<'row'<'col-sm-5'i><'col-sm-7'p>>",
                    searchBuilder: {
                        columns: ['.sb-filter']
                    },
                    language : {
                        searchBuilder: {
                            button: '<span class="fas fa-search"> Filter</span>',
                        }
                    },
                    ajax: {
                        url : '<?=base_url()?>get_users_admin_list',
                        type : 'POST'
                    },
                    columns: [
                        { data: null,
                            searchable : false,
                            orderable : false },
                        { data: 'nama' },
                        { data: 'username' },
                        { data: 'email' },
                        { data: 'active' }
                    ],
                    columnDefs: [
                        {
                            targets: 0,
                            data: null,
                            defaultContent: '<button class="btn-view btn btn-block bg-gradient-success btn-sm"><span class="fas fa-search"></span> View</button>',
                        },
                    ],
                    buttons: [
                        'searchBuilder',
                        'copyHtml5',
                        {
                            extend: 'excelHtml5',
                            text: 'Export Excel',
                            orientation: 'landscape',
                            exportOptions: {
                                columns: [ ':not(.not-export)' ]
                            }
                        },
                        {
                            extend: 'csvHtml5',
                            text: 'Export CSV',
                            orientation: 'landscape',
                            exportOptions: {
                                columns: [ ':not(.not-export)' ]
                            }
                        },
                        {
                            extend: 'pdfHtml5',
                            text: 'Export PDF',
                            orientation: 'landscape',
                            exportOptions: {
                                columns: [ ':not(.not-export)' ]
                            }
                        }
                    ],
                    "initComplete": function(settings, json) {
                    }
                });

                $('#tbl_data1 tbody').on('click','.btn-view',function () {
                    var data = table1.row($(this).parents('tr')[0]).data();
                    document.location.href='<?=base_url()?>users_admin_view/'+data['id_user'];
                });
            });
        </script>

    </section>
</div>