在codeigniter中使用flexigrid库时,我可以很好地显示数据网格,但是当我使用函数排序和搜索时,它无法像以前那样运行。什么都没有改变,只是加载第一页。问题在于搜索和排序,分页功能还可以。
我的代码可能有问题,需要帮助。感谢。
//Controller
public function daftarKomoditi()
{
$colModel['dig10'] = array('Kode Komoditi KBKI',120,TRUE,'left',2);
$colModel['desk10'] = array('Jenis Komoditi',453,TRUE,'left',2);
$gridParams = array(
'width' => '600',
'height' => 'auto',
'rp' => 10,
'singleSelect' => true,
'rpOptions' => '[10,15,20,25,40]',
'pagestat' => 'Displaying: {from} to {to} of {total} items.',
'blockOpacity' => 0.5,
'title' => 'Master Komoditi SHPB 2013',
'showTableToggleBtn' => false
);
$buttons[] = array('Refresh','refresh','test');
$buttons[] = array('separator');
$grid_js = build_grid_js('flex2',site_url("/ajax/getKomoditiList"),$colModel,'id','asc',$gridParams,$buttons);
$data['js_grid'] = $grid_js;
$this->load->view('kualitas/komoditi_list',$data);
}
public function getKomoditiList()
{
$valid_fields = array('dig10,desk10');
$this->flexigrid->validate_post('dig10','asc',$valid_fields);
$records = $this->KualitasModel->getDaftarKomoditi();
$this->output->set_header($this->config->item('json_header'));
foreach ($records['records']->result() as $row) {
$record_items[] = array($row->dig10,
$row->dig10,
ucfirst(strtolower($row->desk10)),
);
}
$this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
}
//Model
function getDaftarKomoditi() //Flexigrid
{
$table_name = "shpb_mkbki_dig10";
$this->db->select('*')->from($table_name);
$this->CI->flexigrid->build_query();
//Get contents
$return['records'] = $this->db->get();
//Build count query
$this->db->select('count(dig10) as record_count')->from($table_name);
$this->CI->flexigrid->build_query(FALSE);
$record_count = $this->db->get();
$row = $record_count->row();
//Get Record Count
$return['record_count'] = $row->record_count;
//Return all
return $return;
}
答案 0 :(得分:0)
以下是我在CodeIgniter 2.2中的Flexigrid实现,查看演示示例并下载:http://ci-flexigrid.sameershemna.com/