Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter + Datatables JS
#1

[eluser]ninjayan[/eluser]
Hi!
Anyone has a working example of integrating datatable in CI?
#2

[eluser]benton.snyder[/eluser]
Controller:

Code:
public function get_tickets()
{
  $this->load->model('tickets');
  echo json_encode($this->tickets->listTickets(NULL, TRUE));  
}

View:

Code:
[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>
#3

[eluser]ninjayan[/eluser]
Thanks! I will try
#4

[eluser]benton.snyder[/eluser]
Just fyi, the [removed] sections referenced the datatables js source and defined html script tags.
#5

[eluser]ninjayan[/eluser]
How about the model? Can I see it? You can email it to me if you don't want others to see it. [email protected]
Thanks!
#6

[eluser]ninjayan[/eluser]
Hello. This is my current code. I'm using ignited datatables

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

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

I add a simple jquery to the
Code:
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?




Theme © iAndrew 2016 - Forum software by © MyBB