<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">Data Agen</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">Data Agen</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">
                                Daftar Data Agen
                            </div>
                        </div>
                        <div class="card-body">
                            <table id="tbl_data1" class="display compact cell-border row-border nowrap" style="width:100%">
                                <thead>
                                    <tr>
                                        <th class="not-export">Action</th>
                                        <th>Nomor</th>
                                        <th>Nama Perusahaan</th>
                                        <th>Nama Pemohon</th>
                                        <th>Sold ID</th>
                                        <th>Email</th>
                                        <th>No. HP</th>
                                        <th>Provinsi</th>
                                        <th>Kabupaten</th>
                                        <th>Kecamatan</th>
                                        <th>Kelurahan</th>
                                        <th>Jumlah Pangkalan</th>
                                    </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            
        </div>
        <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:50,
                    order: [[1, 'asc']],
                    dom: 'Bfrtip',
                    language : {
                        searchBuilder: {
                            button: '<span class="fas fa-search"> Filter</span>',
                        }
                    },
                    ajax: {
                        url : '<?=base_url()?>get_all_agen',
                        type : 'POST'
                    },
                    columns: [
                        { data: null,
                            searchable : false,
                            orderable : false },
                        { data: 'nomor' },
                        { data: 'nama_perusahaan' },
                        { data: 'nama_pemohon' },
                        { data: 'sold_id' },
                        { data: 'email' },
                        { data: 'no_hp' },
                        { data: 'nama_provinsi' },
                        { data: 'nama_kabupaten' },
                        { data: 'nama_kecamatan' },
                        { data: 'nama_kelurahan' },
                        { data: 'jumlah_pangkalan' },
                    ],
                    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',
                        {
                            text: '<span class="fas fa-plus"> Add New</span>',
                            action: function ( e, dt, node, config ) {
                                document.location.href="<?=base_url()?>add_agen";
                            }
                        },
                        '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()?>view_agen/'+data['id_agen'];
                });
            });
        </script>

    </section>
</div>