CodeIgniter + Datatables JS - El Forum - 10-18-2012
[eluser]ninjayan[/eluser]
Hi!
Anyone has a working example of integrating datatable in CI?
CodeIgniter + Datatables JS - El Forum - 10-18-2012
[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>
CodeIgniter + Datatables JS - El Forum - 10-18-2012
[eluser]ninjayan[/eluser]
Thanks! I will try
CodeIgniter + Datatables JS - El Forum - 10-18-2012
[eluser]benton.snyder[/eluser]
Just fyi, the [removed] sections referenced the datatables js source and defined html script tags.
CodeIgniter + Datatables JS - El Forum - 10-19-2012
[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!
CodeIgniter + Datatables JS - El Forum - 11-11-2012
[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",
"<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:
------
Code: $('#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 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?
|