Welcome Guest, Not a member yet? Register   Sign In
Datatables warning: request unknown parameter
#1

Newbie to CI, needs help Smile
Here's my controller code:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Documents extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *         http://example.com/index.php/welcome
     *    - or -  
     *         http://example.com/index.php/welcome/index
     *    - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {    
        $this->load->model('branches_model');
        $this->load->model('documents_model');

        $data['page'] = "documents";
        $data['title'] = "Documents";
        $data['documents'] = array();
        $data['branches'] = $this->branches_model->get_branches_by_type();
        $data['document_types'] = $this->documents_model->get_document_types();

        $this->load->model('groups_model');

        $groups = $this->ion_auth->get_users_groups()->result_array();

        if(count($groups) == 1){
                $data['branding'] = $this->groups_model->get_group_branding($groups[0]['id']);
        }

        if($this->input->post('search_documents')){

            if($this->input->post('location') == "" && $this->input->post('document_type') == "" && $this->input->post('search_terms') == ""){
                echo json_encode(array());
                exit;
            }

            $groups = $this->ion_auth->get_users_groups()->result_array();

            $search_results_raw = array();
            $search_results = array();

            foreach($groups as $group){
                $search_results_raw = array_merge($search_results_raw, $this->documents_model->search_documents_by_location_type($this->input->post('location'), strtolower($this->input->post('document_type')), $this->input->post('search_terms'), $group['id']));
            }

            usort($search_results_raw, function($a, $b){
                return $a['document_update_date'] - $b['document_update_date'];
            });

            // Reverse the array, and remove duplicates etc
            $search_results_raw = array_map("unserialize", array_unique(array_map("serialize", array_reverse($search_results_raw))));

            foreach($search_results_raw as $result){

                if(isset($result['branches.branch_name'])){ $branch_name = $result['branches.branch_name']; } else {$branch_name = 'N\A';};



                if(isset($result['document_expiry_date'])){ $expiry_date = timestamp_to_date($result['document_expiry_date']); } else { $expiry_date = 'N\A';}

                $search_results[] = array(
                    
                    'branch_name' => $branch_name,
                    'document_name' => $result['document_name'],
                    'document_type' => ucfirst($result['document_type']),
                    'document_update_date' => timestamp_to_date($result['document_update_date']),
                    'document_path' => base_url($result['file_path']),
                    'document_expiry_date' => $expiry_date,
                );
            }

            echo json_encode($search_results);
            return TRUE;
        }
        
        $this->template->load('clictime_portal', 'documents', $data);
    }

    public function ajax_get_documents(){
        $branch = $this->input->post('branch');
        $document_type = $this->input->post('document_type');

        //$this->documents_model->get_documents_by_branch_by_type($branch, $document_type);

        json_encode($result);
    }


    
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */


here's my documents views
Code:
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/t/bs/dt-1.10.11/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
        
        $('select').chosen(
              {
                disable_search_threshold: 10,
                allow_single_deselect: true
            }
          );

        $('#search_results tbody').empty();

        var table = $('#search_results').DataTable();
            //


    

    $('#search_documents_form').on('submit', function(event){
        event.preventDefault();

        table.clear();
        

        $.ajax({
            method: 'POST',
            url: '<?php echo base_url($this->uri->uri_string())?>',
            data: {
                'search_documents': '1',
                'location': $('#location').val(),
                'document_type': $('#document_type').val(),
                'search_terms': $('#search_terms').val()

            }
        }).success(function(data){
            var result = $.parseJSON(data);

            if(result.length > 0){
                

                $('.total_results').empty();
                $('.total_results').append(' - ' + result.length +' results');

                $.each(result, function(data){
                    //$('#search_results tbody').append('<tr><td>'+this.branch_name+'</td><td>'+this.document_type+'</td><td>'+this.document_name+'</td><td>'+this.document_update_date+'</td><td>'+ this.document_expiry_date +'</td><td><a href="'+this.document_path+'" target="_blank"><span class="fa fa-arrow-down"></span></a></td></tr>');
                    
                    table.row.add([    
                            this.document_branch_name,
                            this.document_type,
                            this.document_name,
                            this.document_update_date,
                            this.document_expiry_date,
                            '<a href="'+this.document_path+'" target="_blank"><span class="fa fa-arrow-down"></span></a>']).draw();

                });

            } else {
                
                $('#search_results tbody').empty();

                $('.total_results').empty();
                $('.total_results').append();
                $('#search_results tbody').append('<tr><td colspan="6"><center><h3>No Results</h3></center></td></tr>');
            }

        });
    });
});
</script><div class="container">
        <form class="form-horizontal" id="search_documents_form" action="<?php echo base_url($this->uri->uri_string());?>" method="POST">
        <input type="hidden" name="search_documents" value="1">
            <div class="col-lg-12">
            <legend>Search Documents</legend>
                <div class="panel panel-primary">
                  <div class="panel-heading">Search Critera</div>
                  <div class="panel-body">
                  <div class="row">
                      <div class="col-lg-6">
                           <!-- Select Basic -->
                        <div class="form-group">
                          <label class="col-md-4 control-label" for="selectbasic">Location</label>
                          <div class="col-md-8">
                            <select id="location" name="location" class="form-control">
                                <option></option>
                                <?php foreach($branches as $branch_type => $branches_by_type){?>
                                    <optgroup label="<?php echo $branch_type?>">
                                    <?php foreach($branches_by_type as $branch_name){?>
                                        <option value="<?php echo $branch_name['branch_index']?>"><?php echo $branch_name['branch_name']?></option>
                                    <?php }?>
                                    </optgroup>
                                <?php }?>
                            </select>
                          </div>
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <!-- Select Basic -->
                        <div class="form-group">
                          <label class="col-md-4 control-label" for="document_type">Document Type</label>
                          <div class="col-md-8">
                            <select id="document_type" name="document_type" class="form-control">
                                <option></option>
                                 <?php foreach($document_types as $type){?>
                                     <option><?php echo ucfirst($type['document_type']);?></option>
                                 <?php }?>
                            </select>
                          </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-6">
                        <!-- Text input-->
                        <div class="form-group">
                          <label class="col-md-4 control-label" for="search_terms">Search Terms</label>  
                          <div class="col-md-8">
                          <input id="search_terms" name="search_terms" type="text" placeholder="Search Terms" class="form-control input-md">
                            
                          </div>
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <div class="form-group">
                          <div class="col-md-8 col-md-offset-4">
                            <button type="submit" class="btn btn-primary pull-right">
                                    Search
                            </button>
                          </div>
                        </div>
                    </div>
                </div>
                </div>
            </div>
        </form>
    </div>
        <div class="col-lg-12">
            <div class="panel panel-default" style="margin-bottom: 75px;">
              <div class="panel-heading">Search Results <span class="total_results"></span></div>
              <div class="panel-body">

                    <table class="table table-bordered table-hover table-striped" id="search_results">
                        <thead>
                            <th>Branch</th>
                            <th>Document Type</th>
                            <th>Document Name</th>
                            <th>Updated</th>
                            <th>Expiry Date</th>
                            <th style="width: 50px;">Action</th>
                        </thead>
                        <tbody>
                            <tr>
                                <td></td>    
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>                    
                                
                            </tr>
                        </tbody>
                    </table>
              </div>
            </div>
    </div>
and here's the warning in the attatchment.

When I click the warning several times (as many as the results are) the results are shown apart from the first column. I even changed the default NULL values to None, but nothing happened. Can someone help?

Attached Files Thumbnail(s)
   
Reply
#2

SAME ISSUE .

After page loading pop display with DataTables warning: table id=example - Requested unknown parameter '3' for row 50.

how to resolve this ?
Reply
#3

Did you read this and debug your code?

Warning: Requested unknown
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

When you define database use column number of table.

<script type="text/javascript">
$(function(){
var table = $('#sample_3');

// begin first table
table.dataTable({

// Internationalisation. For more info refer to http://datatables.net/manual/i18n
"language": {
"aria": {
"sortAscending": ": activate to sort column ascending",
"sortDescending": ": activate to sort column descending"
},
"emptyTable": "No data available in table",
"info": "Showing1 _START_ to _END_ of _TOTAL_ entries1",
"infoEmpty": "No entries found",
"infoFiltered": "(filtered1 from _MAX_ total entries)",
"lengthMenu": "Show _MENU_ entries",
"search": "Search:",
"zeroRecords": "No matching records found"
},

"bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.

"columns": [{
"orderable": false
}, {
"orderable": true
},{
"orderable": true
},{
"orderable": true
},
"orderable": true
}, {
"orderable": false
}],
"lengthMenu": [
[5, 15, 20, 100, -1],
[5, 15, 20, 100, "All"] // change per page values here
],
// set the initial value
"pageLength": 5,
"pagingType": "bootstrap_full_number",
"language": {
"search": "Search Anything: ",
"lengthMenu": " _MENU_ records",
"paginate": {
"previous":"Prev",
"next": "Next",
"last": "Last",
"first": "First"
}
},
"columnDefs": [{ // set default column settings
'orderable': false,
'targets': [0]
}, {
"searchable": false,
"targets": [0]
}],
"order": [
[1, "desc"]
] // set first column as a default sort by asc
});
});
</script>


Your order-able column incorrect
"columns": [{
"orderable": false
}, {
"orderable": true
},{
"orderable": true
},{
"orderable": true
},
"orderable": true
}, {
"orderable": false
}],
Reply




Theme © iAndrew 2016 - Forum software by © MyBB