Thanks for all the work you put in so far. To make this a Library is an excellent idea.
Can I please request a feature? The possibility of adding a custom filter.
So the final query would be like this:
WHERE (<INSERT AJAX DATATABLE FILTERS HERE>) AND (<INSERT CUSTOM FILTER HERE>)
I made the changes to the code already. All additions are in bold.
public function generate($table, $columns, $index, $cfilter)
{
$sLimit = $this->get_paging();
$sOrder = $this->get_ordering($columns);
$sWhere = $this->get_filtering($columns);
$sCustomWhere = $this->get_customfiltering($sWhere, $cfilter);
$rResult = $this->get_display_data($table, $columns, $sWhere, $sCustomWhere, $sOrder, $sLimit);
$rResultFilterTotal = $this->get_data_set_length();
$aResultFilterTotal = $rResultFilterTotal->result_array();
$iFilteredTotal = $aResultFilterTotal[0]["FOUND_ROWS()"];
$rResultTotal = $this->get_total_data_set_length($table, $index, $sWhere);
$aResultTotal = $rResultTotal->result_array();
$iTotal = $aResultTotal[0]["COUNT($index)"];
return $this->produce_output($columns, $iTotal, $iFilteredTotal, $rResult);
}
protected function get_customfiltering($sWhere, $cfilter){
if($cfilter==""){return "";}
if($sWhere==”“){$sCustomWhere = "WHERE (";}
else{$sCustomWhere =" AND (";}
$sCustomWhere.=$cfilter.”) “;
return $sCustomWhere;
}
protected function get_display_data($table, $columns, $sWhere, $sCustomWhere, $sOrder, $sLimit)
{
$sql = "SELECT SQL_CALC_FOUND_ROWS " . implode(", ", $columns) . "
FROM $table
$sWhere
$sCustomWhere
$sOrder
$sLimit
";
return $this->db->query($sql);
}