Welcome Guest, Not a member yet? Register   Sign In
dropdown filter datatables
#1

I'm stuck on why this filter isn't working on my table.

Code:
<!-- DataTables -->
<link rel="stylesheet" href="<?= base_url() ?>assets/plugins/datatables/dataTables.bootstrap4.css">
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <section class="content">
        <!-- For Messages -->
        <?php $this->load->view('admin/includes/_messages.php') ?>
        <div class="card">
            <div class="card-body">
                <div class="d-inline-block">
                    <h3 class="card-title">
                        <i class="fa fa-list"></i>
                        <?= trans('admin_list') ?>
                    </h3>
                </div>
                <div class="d-inline-block float-right">

                </div>
            </div>
            <div class="card-body">
                <?php echo form_open("/",'class="filterdata"') ?>
                <div class="row">
                    <div class="col-md-3">
                        <div class="form-group">
                            <select name="z" class="form-control" onchange="filter_data()">
                                <option value=""><?= trans('all_admin_types') ?></option>
                                <?php foreach($admin_roles as $admin_role):?>
                                <option value="<?=$admin_role['admin_role_id']?>"><?=$admin_role['admin_role_title']?>
                                </option>
                                <?php endforeach;?>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="form-group">
                            <select name="status" class="form-control" onchange="filter_data()">
                                <option value=""><?= trans('all_status') ?></option>
                                <option value="1"><?= trans('active') ?></option>
                                <option value="0"><?= trans('inactive') ?></option>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <input type="text" name="keyword" class="form-control"
                                placeholder="<?= trans('search_from_here') ?>..." onkeyup="filter_data()" />
                        </div>
                    </div>
                </div>
                <?php echo form_close(); ?>
            </div>
        </div>
    </section>


    <!-- Main content -->
    <section class="content mt10">
        <div class="card">
            <div class="card-body">
                <!-- Load Admin list (json request)-->
                <div class="data_container"></div>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>



<!-- DataTables -->
<script src="<?= base_url() ?>assets/plugins/datatables/jquery.dataTables.js"></script>
<script src="<?= base_url() ?>assets/plugins/datatables/dataTables.bootstrap4.js"></script>

<script>
$(function() {
    $("#example1").DataTable();
});

//------------------------------------------------------------------
function filter_data() {
    $('.data_container').html(
        '<div class="text-center"><img src="<?=base_url('assets/dist/img')?>/loading.png"/></div>');
    $.post('<?=base_url('admin/admin/filterdata')?>', $('.filterdata').serialize(), function() {
        $('.data_container').load('<?=base_url('admin/admin/list_data')?>');
    });
}

//------------------------------------------------------------------
function load_records() {
    $('.data_container').html(
        '<div class="text-center"><img src="<?=base_url('assets/dist/img')?>/loading.png"/></div>');
    $('.data_container').load('<?=base_url('admin/admin/list_data')?>');
}
load_records();

//---------------------------------------------------------------------
$("body").on("change", ".tgl_checkbox", function() {
    $.post('<?=base_url("admin/admin/change_status")?>', {
            '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>',
            id: $(this).data('id'),
            status: $(this).is(':checked') == true ? 1 : 0
        },
        function(data) {
            $.notify("Status Changed Successfully", "success");
        });
});
</script>
Reply
#2

No hard feelings , tell me one thing instead of using datatable and making to filterable using another ajax request. Why you ain't using Ajax datatable ? This will solve all your headache.
Learning Codeigniter 
Reply
#3

(08-06-2022, 05:05 AM)SubrataJ Wrote: No hard feelings , tell me one thing instead of using datatable and making to filterable using another ajax request. Why you ain't using Ajax datatable ? This will solve all your headache.

Because I'm very new and I have no idea what I'm doing. I just need help. I will read about that.
Reply
#4

(This post was last modified: 08-06-2022, 06:13 AM by SubrataJ.)

@bikebetty follow this tutorial you will get to know how to implement ajax datatable , if you still have issues lemme know I will surely help you out.
Ajax Datatable Tutorials CI4 (Demo ain't working but the given codes are right).
Learning Codeigniter 
Reply
#5

(08-06-2022, 06:08 AM)SubrataJ Wrote: @bikebetty follow this tutorial you will get to know how to implement ajax datatable , if you still have issues lemme know I will surely help you out.
Ajax Datatable Tutorials CI4 (Demo ain't working but the given codes are right).

Thank you.
Reply
#6

(This post was last modified: 08-07-2022, 08:58 AM by SubrataJ.)

Cheers happy coding  Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB