EllisLab text mark
Advanced Search
     
CodeIgniter + Datatables JS
Posted: 18 October 2012 11:52 PM   [ Ignore ]
Avatar
Joined: 2012-10-02
71 posts

Hi!
Anyone has a working example of integrating datatable in CI?

 
Posted: 19 October 2012 12:33 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2012-10-17
27 posts

Controller:

public function get_tickets()
 
{
  $this
->load->model('tickets');
  echo 
json_encode($this->tickets->listTickets(NULLTRUE));  
 

View:

[removed][removed]
<link href="<?=$this->config->base_url();?>includes/datatables/css/jquery.dataTables.css" type="text/css" rel="stylesheet" />

[removed]

$(document).ready(function() {

 
// initialize tickets datatable 
 
oTable = $('#tickets').dataTable{
  
"sScrollX""100%",
  
"sScrollXInner""100%",
  
"bProcessing"true,
  
"bServerSide"true,
  
"bJQueryUI"true,
  
"sAjaxSource"'<?=$this->config->site_url();?>/main/get_tickets'
 
);
[removed] 
<div id="datatables">
  <
table id="tickets">
      <
thead>
          <
tr>
              <
th>ID</th>
              <
th>Last Update</th>
              <
th>Created</th>
              <
th>Priority</th>
              <
th>Subject</th>
              <
th>Description</th>
              <
th>Flagged</th>
              <
th>Owner</th>
              <
th>Group</th>
          </
tr>
      </
thead>
      <
tbody>
          <
tr>
              <
td>Row 1 Data 1</td>
              <
td>Row 1 Data 2</td>
              <
td>Row 1 Data 3</td>
              <
td>Row 1 Data 4</td>
              <
td>Row 1 Data 5</td>
              <
td>Row 1 Data 6</td>
              <
td>Row 1 Data 7</td>
              <
td>Row 1 Data 8</td>
              <
td>Row 1 Data 9</td>
          </
tr>
      </
tbody>
  </
table>
 </
div
 
Posted: 19 October 2012 12:42 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2012-10-02
71 posts

Thanks! I will try

 
Posted: 19 October 2012 12:46 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2012-10-17
27 posts

Just fyi, the [removed] sections referenced the datatables js source and defined html script tags.

 
Posted: 19 October 2012 04:25 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2012-10-02
71 posts

How about the model? Can I see it? You can email it to me if you don’t want others to see it. .(JavaScript must be enabled to view this email address)
Thanks!

 
Posted: 12 November 2012 02:48 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2012-10-02
71 posts

Hello. This is my current code. I’m using ignited datatables

controller:
—————-

public function get_transaction_types()
 
{
  $this
->load->library('datatables');
  
$this->datatables
     
->select('name, days'FALSE)
     ->
from('transaction_types')
     ->
add_column("Actions",
      
"<form id='edit_form' method='post' action='settings/edit_transaction_type/$1' class='left'>
      <input type='hidden' value='$1' id='trans_type' name='trans_type' readonly />
      <button class='settings-action-btn' title='Update'>
      <img src='assets/images/icons/edit.png' alt='Update' />
      </button>
      </form>
      <form id='delete_transaction_type_form' method='post' action='settings/delete_transaction_type/$1' method='post' class='right'>
      <input type='hidden' value='$1' id='delete_trans_type' name='delete_trans_type' readonly />
      <button class='settings-action-btn' title='Delete'>
      <img src='assets/images/icons/delete.png' alt='Delete' />
      </button>
      </form>"
,
      
"name");
  echo 
$this->datatables->generate();
 

views:
———

$('#transaction_type_table').dataTable({
   
"sPaginationType""full_numbers",
   
"bProcessing"true,
   
"bServerSide"true,
   
"bJQueryUI"true,
   
"bDeferRender"true,
   
"sAjaxSource""<?php echo base_url(); ?>/settings/get_transaction_types",
   
"sServerMethod""POST",
   
"aoColumnDefs"[{
    
'bSortable'false,
    
'aTargets'[2]
   }]
  }
); 

I add a simple jquery to the

edit_form 

which is found at the controller and cannot be accessed since its on the controller. Is there a way that I can transfer ingnited datatables code to views?