Hi everyone…
Thanks for letting me joining this forum…
I’ve bought grocery crud enterprise, and for basic needs, it suits me well and help me alot. Problem arise when i want to use some custom query and use set model. Despite of the table show up sucessfully, the search and the pagination didnt work. it only show 10, 20 or 50 first data (depend on the setting per page). I am using the code example as show on github here
i am inserting code that i use here…i am appreciate for the help… and sorry for my bad english.
<?php defined('BASEPATH') OR exit('No direct script access allowed');
use GroceryCrud\Core\Model;
use GroceryCrud\Core\Model\ModelFieldType;
class M_custombaranggc extends Model
{
protected $ci;
protected $db;
protected $limit = 10;
function __construct($databaseConfig)
{
$this->setDatabaseConnection($databaseConfig);
$this->ci = & get_instance();
$this->db = $this->ci->db;
}
public function getFieldTypes($tableName)
{
$fieldTypes = parent::getFieldTypes($tableName);
$tahunPerolehanFieldType = new ModelFieldType();
$tahunPerolehanFieldType->dataType = 'varchar';
$uraianbarangFieldType = new ModelFieldType();
$uraianbarangFieldType->dataType = 'varchar';
$fieldTypes['tahunperolehan'] = $tahunPerolehanFieldType;
$fieldTypes['uraianbarang'] = $uraianbarangFieldType;
return $fieldTypes;
}
protected function _getQueryModelObject() {
// All the custom stuff here
$this->db->select('baranggc.id, baranggc.kd_lokasi, baranggc.kd_brg, baranggc.merk_type as merk_type, t_subkelompok.ur_sskel as uraianbarang, baranggc.no_aset, year(baranggc.tgl_perlh) as tahunperolehan,
if(tercatat=1,"DBR",if(tercatat=2,"DBL","KIB")) as tercatat,
if(kondisi=1,"Baik",if(kondisi=2,"Rusak Ringan","Rusak Berat")) as kondisi,
if(flag_sap="y","Intra","Ekstra") as "flag_sap" ', false);
$this->db->join('t_subkelompok', 't_subkelompok.kd_brg = baranggc.kd_brg', 'left');
if (!empty($this->_filters)) {
foreach ($this->_filters as $filter_name => $filter_value) {
if ($filter_name === 'uraianbarang') {
if (is_array($filter_value))
{
foreach ($filter_value as $value)
{
$this->db->like('t_subkelompok.ur_sskel', $value);
}
} else {
$this->db->like('t_subkelompok.ur_sskel', $filter_value);
}
} else {
if (is_array($filter_value)) {
foreach ($filter_value as $value)
{
$this->db->like($filter_name, $value);
}
} else {
$this->db->like($filter_name, $filter_value);
}
}
}
}
$this->db->limit($this->limit);
$this->db->offset($this->limit * ($this->page - 1));
$order_by = $this->orderBy;
$sorting = $this->sorting;
if ($order_by !== null) {
$this->db->order_by($order_by. " " . $sorting);
}
return $this->db->get($this->tableName);
}
public function getList() {
return $this->_getQueryModelObject()->result_array();
}
public function getTotalItems() {
if (!empty($this->_filters)) {
return $this->_getQueryModelObject()->num_rows();
}
// If we don't have any filtering it is faster to have the default total items // In case this is more complicated you can add your own code here
return parent::getTotalItems(); } }