diff --git a/application/libraries/Datatables.php b/application/libraries/Datatables.php index 0160b5c..8f81218 100644 --- a/application/libraries/Datatables.php +++ b/application/libraries/Datatables.php @@ -22,6 +22,7 @@ class Datatables private $ci; private $table; private $distinct; + private $count_column; private $group_by = array(); private $select = array(); private $joins = array(); @@ -242,6 +243,18 @@ public function unset_column($column) return $this; } + /** + * Sets the column used for counting improving performance + * + * @param string $column + * @return mixed + */ + public function set_count_column($column) + { + $this->count_column = $column; + return $this; + } + /** * Builds all the necessary query segments and performs the main query based on results set from chained statements * @@ -407,6 +420,9 @@ private function get_total_results($filtering = FALSE) if($filtering) $this->get_filtering(); + if(strlen($this->count_column) > 0) + $this->ci->db->select($this->count_column); + foreach($this->joins as $val) $this->ci->db->join($val[0], $val[1], $val[2]); @@ -604,8 +620,8 @@ private function jsonify($result = FALSE) return '{' . join(',', $json) . '}'; } } - - /** + + /** * returns the sql statement of the last query run * @return type */