Datatable is not displaying on view page











up vote
0
down vote

favorite












I am using CodeIgniter, Datatable is not working. I am displaying all the records in the data table. but it's not displaying. I am getting my view page like this.



enter image description here



I am getting the records from my model. There is no issue with the model. Let me know if require the model code.



Would you help me out on this issue?



view



<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<table cellspacing="0" id="team_members_list">
<thead>
<tr>
<th> Employee Name </th>
<th> EMP ID</th>
<th> Mobile No. </th>
<th> Designation </th>
<th> Role </th>
<th> Status </th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>


js



$(document).ready(function() {
var oTable = $('#team_members_list').DataTable({
'responsive': true,
//"processing": true,
// "serverSide": true,
"pageLength": 10,
"ajax": {
"url": baseUrl + "/Employee_control/team_members",
"type": "POST"
},
"columns": [{
"data": "name"
},
{
"data": "employee_id"
},
{
"data": "mobileno"
},
{
"data": "emp_designation"
},
{
"data": "emp_role_name"
}
],
'responsive': true
});
});


Controller



public function team_members(){ 
$draw = intval($this->input->get("draw"));
$start = intval($this->input->get("start"));
$length = intval($this->input->get("length"));
$books = $this->Employee_model->getTotalList_of_TeamLeader();

$data['draw'] = 1;
$data['recordsTotal'] = count($books);
$data['recordsFiltered'] = count($books);
// // $n=1;
foreach ($books as $key => $row)
{
$arr_result = array(
// "Sr.No" => $n,
"id" => base64_encode($this->encryption->encrypt($row->id)),
"name" => $row->firstname.' ' .$row->lastname,
"employee_id" => $row->employee_id,
"mobileno" => $row->mobileno,
"emp_designation" => $row->emp_designation,
"emp_role_name" => $row->emp_role_name,
"emp_teamLeader" => $row->team_leadername
);

$data['data'] = $arr_result;
}
echo json_encode($data);
exit;

}









share|improve this question


























    up vote
    0
    down vote

    favorite












    I am using CodeIgniter, Datatable is not working. I am displaying all the records in the data table. but it's not displaying. I am getting my view page like this.



    enter image description here



    I am getting the records from my model. There is no issue with the model. Let me know if require the model code.



    Would you help me out on this issue?



    view



    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
    <table cellspacing="0" id="team_members_list">
    <thead>
    <tr>
    <th> Employee Name </th>
    <th> EMP ID</th>
    <th> Mobile No. </th>
    <th> Designation </th>
    <th> Role </th>
    <th> Status </th>
    </tr>
    </thead>
    <tbody>
    </tbody>
    </table>
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>


    js



    $(document).ready(function() {
    var oTable = $('#team_members_list').DataTable({
    'responsive': true,
    //"processing": true,
    // "serverSide": true,
    "pageLength": 10,
    "ajax": {
    "url": baseUrl + "/Employee_control/team_members",
    "type": "POST"
    },
    "columns": [{
    "data": "name"
    },
    {
    "data": "employee_id"
    },
    {
    "data": "mobileno"
    },
    {
    "data": "emp_designation"
    },
    {
    "data": "emp_role_name"
    }
    ],
    'responsive': true
    });
    });


    Controller



    public function team_members(){ 
    $draw = intval($this->input->get("draw"));
    $start = intval($this->input->get("start"));
    $length = intval($this->input->get("length"));
    $books = $this->Employee_model->getTotalList_of_TeamLeader();

    $data['draw'] = 1;
    $data['recordsTotal'] = count($books);
    $data['recordsFiltered'] = count($books);
    // // $n=1;
    foreach ($books as $key => $row)
    {
    $arr_result = array(
    // "Sr.No" => $n,
    "id" => base64_encode($this->encryption->encrypt($row->id)),
    "name" => $row->firstname.' ' .$row->lastname,
    "employee_id" => $row->employee_id,
    "mobileno" => $row->mobileno,
    "emp_designation" => $row->emp_designation,
    "emp_role_name" => $row->emp_role_name,
    "emp_teamLeader" => $row->team_leadername
    );

    $data['data'] = $arr_result;
    }
    echo json_encode($data);
    exit;

    }









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am using CodeIgniter, Datatable is not working. I am displaying all the records in the data table. but it's not displaying. I am getting my view page like this.



      enter image description here



      I am getting the records from my model. There is no issue with the model. Let me know if require the model code.



      Would you help me out on this issue?



      view



      <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
      <table cellspacing="0" id="team_members_list">
      <thead>
      <tr>
      <th> Employee Name </th>
      <th> EMP ID</th>
      <th> Mobile No. </th>
      <th> Designation </th>
      <th> Role </th>
      <th> Status </th>
      </tr>
      </thead>
      <tbody>
      </tbody>
      </table>
      <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
      <script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>


      js



      $(document).ready(function() {
      var oTable = $('#team_members_list').DataTable({
      'responsive': true,
      //"processing": true,
      // "serverSide": true,
      "pageLength": 10,
      "ajax": {
      "url": baseUrl + "/Employee_control/team_members",
      "type": "POST"
      },
      "columns": [{
      "data": "name"
      },
      {
      "data": "employee_id"
      },
      {
      "data": "mobileno"
      },
      {
      "data": "emp_designation"
      },
      {
      "data": "emp_role_name"
      }
      ],
      'responsive': true
      });
      });


      Controller



      public function team_members(){ 
      $draw = intval($this->input->get("draw"));
      $start = intval($this->input->get("start"));
      $length = intval($this->input->get("length"));
      $books = $this->Employee_model->getTotalList_of_TeamLeader();

      $data['draw'] = 1;
      $data['recordsTotal'] = count($books);
      $data['recordsFiltered'] = count($books);
      // // $n=1;
      foreach ($books as $key => $row)
      {
      $arr_result = array(
      // "Sr.No" => $n,
      "id" => base64_encode($this->encryption->encrypt($row->id)),
      "name" => $row->firstname.' ' .$row->lastname,
      "employee_id" => $row->employee_id,
      "mobileno" => $row->mobileno,
      "emp_designation" => $row->emp_designation,
      "emp_role_name" => $row->emp_role_name,
      "emp_teamLeader" => $row->team_leadername
      );

      $data['data'] = $arr_result;
      }
      echo json_encode($data);
      exit;

      }









      share|improve this question













      I am using CodeIgniter, Datatable is not working. I am displaying all the records in the data table. but it's not displaying. I am getting my view page like this.



      enter image description here



      I am getting the records from my model. There is no issue with the model. Let me know if require the model code.



      Would you help me out on this issue?



      view



      <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
      <table cellspacing="0" id="team_members_list">
      <thead>
      <tr>
      <th> Employee Name </th>
      <th> EMP ID</th>
      <th> Mobile No. </th>
      <th> Designation </th>
      <th> Role </th>
      <th> Status </th>
      </tr>
      </thead>
      <tbody>
      </tbody>
      </table>
      <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
      <script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>


      js



      $(document).ready(function() {
      var oTable = $('#team_members_list').DataTable({
      'responsive': true,
      //"processing": true,
      // "serverSide": true,
      "pageLength": 10,
      "ajax": {
      "url": baseUrl + "/Employee_control/team_members",
      "type": "POST"
      },
      "columns": [{
      "data": "name"
      },
      {
      "data": "employee_id"
      },
      {
      "data": "mobileno"
      },
      {
      "data": "emp_designation"
      },
      {
      "data": "emp_role_name"
      }
      ],
      'responsive': true
      });
      });


      Controller



      public function team_members(){ 
      $draw = intval($this->input->get("draw"));
      $start = intval($this->input->get("start"));
      $length = intval($this->input->get("length"));
      $books = $this->Employee_model->getTotalList_of_TeamLeader();

      $data['draw'] = 1;
      $data['recordsTotal'] = count($books);
      $data['recordsFiltered'] = count($books);
      // // $n=1;
      foreach ($books as $key => $row)
      {
      $arr_result = array(
      // "Sr.No" => $n,
      "id" => base64_encode($this->encryption->encrypt($row->id)),
      "name" => $row->firstname.' ' .$row->lastname,
      "employee_id" => $row->employee_id,
      "mobileno" => $row->mobileno,
      "emp_designation" => $row->emp_designation,
      "emp_role_name" => $row->emp_role_name,
      "emp_teamLeader" => $row->team_leadername
      );

      $data['data'] = $arr_result;
      }
      echo json_encode($data);
      exit;

      }






      php ajax html5 datatable codeigniter-3






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 6:47









      user9437856

      362111




      362111
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          You are continually overwriting the same variable in your controller to build up the data, so change it to use to add the data...



          $arr_result = ;    // Initialise the array
          foreach ($books as $key => $row)
          {
          $arr_result = array(
          // "Sr.No" => $n,
          "id" => base64_encode($this->encryption->encrypt($row->id)),
          "name" => $row->firstname.' ' .$row->lastname,
          "employee_id" => $row->employee_id,
          "mobileno" => $row->mobileno,
          "emp_designation" => $row->emp_designation,
          "emp_role_name" => $row->emp_role_name,
          "emp_teamLeader" => $row->team_leadername
          );

          }
          // Add to main data after loop has finished
          $data['data'] = $arr_result;





          share|improve this answer





















          • Thanks for the answer,I updated your code with my code. Now i am getting 37 records but still my view not displaying. I mean records are not displaying like list in datatable
            – user9437856
            Nov 11 at 7:08












          • Oh! wait I think there is some issue from my end. give me some time to check.
            – user9437856
            Nov 11 at 7:19










          • Have you checked your console? Normally you can check returning data in Browser->Network tab , if some errors caused on front-end you can see them on console tab as well
            – Rega
            Nov 11 at 8:48













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246477%2fdatatable-is-not-displaying-on-view-page%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          You are continually overwriting the same variable in your controller to build up the data, so change it to use to add the data...



          $arr_result = ;    // Initialise the array
          foreach ($books as $key => $row)
          {
          $arr_result = array(
          // "Sr.No" => $n,
          "id" => base64_encode($this->encryption->encrypt($row->id)),
          "name" => $row->firstname.' ' .$row->lastname,
          "employee_id" => $row->employee_id,
          "mobileno" => $row->mobileno,
          "emp_designation" => $row->emp_designation,
          "emp_role_name" => $row->emp_role_name,
          "emp_teamLeader" => $row->team_leadername
          );

          }
          // Add to main data after loop has finished
          $data['data'] = $arr_result;





          share|improve this answer





















          • Thanks for the answer,I updated your code with my code. Now i am getting 37 records but still my view not displaying. I mean records are not displaying like list in datatable
            – user9437856
            Nov 11 at 7:08












          • Oh! wait I think there is some issue from my end. give me some time to check.
            – user9437856
            Nov 11 at 7:19










          • Have you checked your console? Normally you can check returning data in Browser->Network tab , if some errors caused on front-end you can see them on console tab as well
            – Rega
            Nov 11 at 8:48

















          up vote
          0
          down vote



          accepted










          You are continually overwriting the same variable in your controller to build up the data, so change it to use to add the data...



          $arr_result = ;    // Initialise the array
          foreach ($books as $key => $row)
          {
          $arr_result = array(
          // "Sr.No" => $n,
          "id" => base64_encode($this->encryption->encrypt($row->id)),
          "name" => $row->firstname.' ' .$row->lastname,
          "employee_id" => $row->employee_id,
          "mobileno" => $row->mobileno,
          "emp_designation" => $row->emp_designation,
          "emp_role_name" => $row->emp_role_name,
          "emp_teamLeader" => $row->team_leadername
          );

          }
          // Add to main data after loop has finished
          $data['data'] = $arr_result;





          share|improve this answer





















          • Thanks for the answer,I updated your code with my code. Now i am getting 37 records but still my view not displaying. I mean records are not displaying like list in datatable
            – user9437856
            Nov 11 at 7:08












          • Oh! wait I think there is some issue from my end. give me some time to check.
            – user9437856
            Nov 11 at 7:19










          • Have you checked your console? Normally you can check returning data in Browser->Network tab , if some errors caused on front-end you can see them on console tab as well
            – Rega
            Nov 11 at 8:48















          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          You are continually overwriting the same variable in your controller to build up the data, so change it to use to add the data...



          $arr_result = ;    // Initialise the array
          foreach ($books as $key => $row)
          {
          $arr_result = array(
          // "Sr.No" => $n,
          "id" => base64_encode($this->encryption->encrypt($row->id)),
          "name" => $row->firstname.' ' .$row->lastname,
          "employee_id" => $row->employee_id,
          "mobileno" => $row->mobileno,
          "emp_designation" => $row->emp_designation,
          "emp_role_name" => $row->emp_role_name,
          "emp_teamLeader" => $row->team_leadername
          );

          }
          // Add to main data after loop has finished
          $data['data'] = $arr_result;





          share|improve this answer












          You are continually overwriting the same variable in your controller to build up the data, so change it to use to add the data...



          $arr_result = ;    // Initialise the array
          foreach ($books as $key => $row)
          {
          $arr_result = array(
          // "Sr.No" => $n,
          "id" => base64_encode($this->encryption->encrypt($row->id)),
          "name" => $row->firstname.' ' .$row->lastname,
          "employee_id" => $row->employee_id,
          "mobileno" => $row->mobileno,
          "emp_designation" => $row->emp_designation,
          "emp_role_name" => $row->emp_role_name,
          "emp_teamLeader" => $row->team_leadername
          );

          }
          // Add to main data after loop has finished
          $data['data'] = $arr_result;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 7:02









          Nigel Ren

          23k61832




          23k61832












          • Thanks for the answer,I updated your code with my code. Now i am getting 37 records but still my view not displaying. I mean records are not displaying like list in datatable
            – user9437856
            Nov 11 at 7:08












          • Oh! wait I think there is some issue from my end. give me some time to check.
            – user9437856
            Nov 11 at 7:19










          • Have you checked your console? Normally you can check returning data in Browser->Network tab , if some errors caused on front-end you can see them on console tab as well
            – Rega
            Nov 11 at 8:48




















          • Thanks for the answer,I updated your code with my code. Now i am getting 37 records but still my view not displaying. I mean records are not displaying like list in datatable
            – user9437856
            Nov 11 at 7:08












          • Oh! wait I think there is some issue from my end. give me some time to check.
            – user9437856
            Nov 11 at 7:19










          • Have you checked your console? Normally you can check returning data in Browser->Network tab , if some errors caused on front-end you can see them on console tab as well
            – Rega
            Nov 11 at 8:48


















          Thanks for the answer,I updated your code with my code. Now i am getting 37 records but still my view not displaying. I mean records are not displaying like list in datatable
          – user9437856
          Nov 11 at 7:08






          Thanks for the answer,I updated your code with my code. Now i am getting 37 records but still my view not displaying. I mean records are not displaying like list in datatable
          – user9437856
          Nov 11 at 7:08














          Oh! wait I think there is some issue from my end. give me some time to check.
          – user9437856
          Nov 11 at 7:19




          Oh! wait I think there is some issue from my end. give me some time to check.
          – user9437856
          Nov 11 at 7:19












          Have you checked your console? Normally you can check returning data in Browser->Network tab , if some errors caused on front-end you can see them on console tab as well
          – Rega
          Nov 11 at 8:48






          Have you checked your console? Normally you can check returning data in Browser->Network tab , if some errors caused on front-end you can see them on console tab as well
          – Rega
          Nov 11 at 8:48




















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246477%2fdatatable-is-not-displaying-on-view-page%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          Bicuculline

          さくらももこ