JQuery DataTable with Ignited-Datatables CodeIgniter

Update:

Finally, I found a solution to this problem. If you encounter the same problem as mine, you can try visiting the link

I'm having a problem when you want to integrate jQuery DataTables with the CodeIgniter Ignited-Datatables Library

When I use the default DataTables property sServerMethod , which is "GET", I got a json response with data from my php. However, since CodeIgniter uses mail, I am stuck in loading server data, although the function returns me the correct json output.

enter image description here

guide, sServerMethod "POST". , .

JSON sServerMethod GET ( json, , )

{
"sEcho": 0,
"iTotalRecords": 10,
"iTotalDisplayRecords": 10,
"aaData": [
    [
        "Munauwar",
        "Syed",
        "Mr",
        "6012345678",
        "0000-00-00",
        "basikal"
    ],        
    [
        "Mak",
        "Je Wei",
        "Mr",
        "6012345678",
        "0000-00-00",
        "motor"
    ]
],
"sColumns": "first_name,last_name,salutation,number,birthday,group_name"}

JSON sServerMethod POST

{
"sEcho": 1,
"iTotalRecords": 10,
"iTotalDisplayRecords": 0,
"aaData": [],
"sColumns": "first_name,last_name,salutation,number,birthday,group_name"}

javascript

$('#table1').dataTable({
        "bProcessing": true,
        "bServerSide": true,            
        "sPaginationType": "bootstrap",
        "sAjaxSource": config.base_url + "contact/popup_contact",
        "sServerMethod": "POST"

    });

function popup_contact()
{
    $this->datatables
         ->select('first_name,last_name,salutation,number,birthday,group_name')
         ->from('tb_contact')
         ->join('tb_contact_group', 'tb_contact.contact_group_id = tb_contact_group.contact_group_id');          

    echo $this->datatables->generate();             

}
+2
3

, , : $config ['csrf_protection'] = true;// Codeigniter

aoData.push fnServerData:

"fnServerData": function(sSource, aoData, fnCallback) {
            aoData.push({name: '<?php echo $this->security->get_csrf_token_name(); ?>', value: '<?php echo $this->security->get_csrf_hash(); ?>'});
                $.ajax({
                    'dataType': 'json',
                    'type': 'POST',
                    'url': sSource,
                    'data': aoData,
                    'success': fnCallback
                });
            }
+2
$('#smstable').dataTable({
"bProcessing": true,
"bServerSide": true,
"iDisplayLength": 20,
//"bPaginate": true,
"bAutoWidth": false,
"iDisplayStart": 0,
"bLengthChange": false,//for sorting 10,20,30,50 ....
"sAjaxSource": "././myadmin/ajaxadmin/dt_sms",
"aaSorting": [[ 1, "desc" ]],
"sPaginationType": "full_numbers",
"aoColumns":[
    {"bSearchable": false,"bSortable": false,"bVisible": false},
    {"bSearchable": true,"bSortable": true},
    {"bSearchable": false,"bSortable": false},
    {"bSearchable": true,"bSortable": true},
    {"bSearchable": false,"bSortable": true},
    {"bSearchable": false,"bSortable": false}
],
"fnServerData": function(sSource, aoData, fnCallback){
    $.ajax(
          {
            'dataType': 'json',
            'type'  : 'POST',
            'url'    : sSource,
            'data'  : aoData,
            'success' : fnCallback
          }
      );//end ajx
    // console.log(fnCallback);
}    

});//end datable

Just check my code and check if you missed something. That code works very fine with me.
+1

Anytime you get stuck while loading data from the server ..... this basically causes a set of columns. Just recount the "aoColumns" array and make sure that it exactly matches the set of heads in your view file.

This has happened to me again and again ..... and the only solution has always been a set of column arrays.

0
source

Source: https://habr.com/ru/post/1629545/


All Articles