public function grid()
{
$iTotal = $this->db->count_all('glossary');
$this->db->start_cache();
$this->db->from('glossary');
/* Searching */
if ($this->input->post('sSearch') != '') {
$q = $this->input->post('sSearch', TRUE);
$this->db->orlike('g_term', $q);
$this->db->orlike('g_definition', $q);
}
/* Sorting */
if ($this->input->post('iSortCol_0')) {
$sort_col = $this->input->post('iSortCol_0');
for ($i = 0; $i < $sort_col; $i++) {
$this->db->order_by($this->_column_to_field($this->input->post('iSortCol_' . $i)), $this->input->post('iSortDir_' . $i));
}
} else {
$this->db->order_by('g_id', 'desc');
}
$this->db->stop_cache();
$iFilteredTotal = $this->db->count_all_results();
$this->db->start_cache();
/* Limit */
if ($this->input->post('iDisplayStart') && $this->input->post('iDisplayLength') != '-1') {
$this->db->limit($this->input->post('iDisplayLength'), $this->input->post('iDisplayStart'));
} elseif ($this->input->post('iDisplayLength')) {
$this->db->limit($this->input->post('iDisplayLength'));
}
$query = $this->db->get();
$output = '{';
$output .= '"sEcho": ' . $this->input->post('sEcho') . ', ';
$output .= '"iTotalRecords": ' . $iTotal . ', ';
$output .= '"iTotalDisplayRecords": ' . $iFilteredTotal . ', ';
$output .= '"aaData": [ ';
foreach ($query->result_array() as $row) {
$title = anchor('admin/kb/glossary/edit/' . $row['g_id'], $row['g_term']);
$output .= "[";
$output .= '"' . addslashes($title) . '",';
$output .= '"' . addslashes(character_limiter($row['g_definition'], 50)) . '",';
$output .= '"<input type=\\"checkbox\\" name=\\"g_id[]\\" value=\\"' . $row['g_id'] . '\\" />"';
$output .= "],";
}
$output = substr_replace($output, "", -1);
$output .= '] }';
echo $output;
}