Codeigniter - How to fetch datatable data from ajax?

Form 

<table class="table table-striped table-hover dt-responsive display nowrap" id="amazonfees">
    <thead>
    <tr>
        <th>User</th>
        <th>Date</th>
        <th>Invoice No</th>
        <th>Amount</th>
        <th>Shipping Charge</th>
        <th>PG Listing & Other Charge</th>
        <th>Storage Fee</th>
        <th>Contractor Amount</th>
        <th>Professional Amount</th>
        <th>Rent Amount</th>
        <th>Brokerage Amount</th>
        <th>Sub Total</th>
        <th>Action</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
</table>

JS

<script type="text/javascript">
    $.noConflict();
    jQuery(function ($) {
        $('#amazonfees').DataTable({
            "bSort": true,
            "pageLength": 10,
            "iDisplayLength": 10,
            "paging": true,
            "bInfo": true,
            "bDestroy": true,
            "bFilter": true,
            "searching": true,
            "bPaginate": true,
            "bAutoWidth": true,
            "bLengthChange": false,
            "bProcessing": true,
            "language": {
                "loadingRecords": '&nbsp;',
                "processing": '<i class="fa fa-spinner fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading..n.</span>'            },
            'ajax': {
                "type": "POST",
                "url": "<?php echo base_url()."admin/amazon_fees_detail/get_fees_details"; ?>",
                "data": function (d) {
                },
                "dataType": 'json',
                "dataSrc": "",
                "timeout":1000000,
                "async": true,
                "cache": true            },
            'columnDefs': [
                {
                    targets: 0,
                    className: "dt-center",
                    render: function (data, type, row) {
                        return  row['username'];
                    }
                },
                {
                    targets: 1,
                    render: function (data, type, row) {
                        return  row['date'];
                    }
                },
                {
                    targets: 2,
                    render: function (data, type, row) {
                        return  row['invoice_no'];
                    }
                },
                {
                    targets: 3,
                    className: "dt-center",
                    render: function (data, type, row) {
                        return  row['amount'];

                    }
                },
                {
                    targets: 4,
                    className: "dt-center",
                    render: function (data, type, row) {
                        return  row['shipping_charge'];
                    }
                },
                {
                    targets: 5,
                    className: "dt-center",
                    render: function (data, type, row) {
                        return  row['pg_listing_other_charge'];
                    }
                },
                {
                    targets: 6,
                    className: "dt-center",
                    render: function (data, type, row) {
                        return  row['storage_fee'];
                    }
                },
                {
                    targets: 7,
                    className: "dt-center",
                    render: function (data, type, row) {
                        return  row['contractor_amount'];
                    }
                },
                {
                    targets: 8,
                    className: "dt-center",
                    render: function (data, type, row) {
                        return  row['professional_amount'];
                    }
                },
                {
                    targets: 9,
                    className: "dt-center",
                    render: function (data, type, row) {
                        return  row['rent_amount'];
                    }
                },
                {
                    targets: 10,
                    className: "dt-center",
                    render: function (data, type, row) {
                        return  row['brokerage_amount'];
                    }
                },
                {
                    targets: 11,
                    className: "dt-center",
                    render: function (data, type, row) {
                        return  row['sub_total'];
                    }
                },
                {
                    targets: 12,
                    render: function (data, type, row) {
                        return  '<a href="<?php echo base_url() . "admin/amazon_fees_detail/deleteamazonfeesdetail/";?>'+ row['id'] +'">Delete</a>';
                    }
                }
            ]
        });
    });
</script>


Controller

public function get_fees_details(){    ini_set('memory_limit', '-1');    ini_set('max_execution_time', 0);    $result['amazonfeesdetail'] = $this->calculation_model->getamazonfeesdetails(array('status'=>0));    echo json_encode($result['amazonfeesdetail']);exit;}

Popular posts from this blog

Ajax Toggle(on/off) on-click Update

Yii Framework In Update Time View Image In Form