可以在不编辑分页库的情况下在Codeigniter中使用AJAX分页吗?编辑分页库会让生活变得更容易吗?
发布于 2011-07-24 06:48:47
您应该不需要编辑分页库。AJAX都是前端的兄弟。您只需创建一个显示结果列表的视图,然后创建另一个包含div的视图,您将使用列表视图填充该div。在结果容器中,您可以使用另一个视图将ajax响应加载到div中。
发布于 2013-05-16 00:30:40
在加载视图之前添加jquery。
//Define model function with limit
public function modelFunction($limit=0)
{
$this->db->select("....col_name....");
//....................
//.........
$this->db->limit(10,$limit)->order_by('id', 'desc');
return $this->db->get()->result_array();
}
//Define controller function with limit
function controllerFunction($limit = 0)
{
$config['base_url'] = path_to_controllerFunction
$config['total_rows'] = call_to_total_count_function;
$config['per_page'] = 10;
$data["total"] = call_to_total_count_function;
$config['use_page_numbers'] = TRUE;
$data["per_page"] = 10;
$config['full_tag_open'] = "<div class = 'pagination'>";
$config['full_tag_close'] = "</div>";
//$config['additional_param'] = 'serialize_form()';
$config['div'] = '#div_to_load_result'; /* Here #content is the CSS selector for target DIV */
//$config['js_rebind'] = "alert('it works !!'); "; /* if you want to bind extra js code */
$this->load->library('table');
$this->jquery_pagination->initialize($config);
$html = $this->jquery_pagination->create_links();
$html .= '<br>';
//$this->table->function = 'htmlspecialchars';
//$this->table->set_heading('Delivery','image','time','delivery','old');
$html .= $this->table->generate($this->modelname->modelFunction( $limit ));
echo $html;
}
// first time loading result in controller
function index()
{
$config['base_url'] = controllerFunction
$config['total_rows'] = total_number_of_result;
$config['per_page'] = 10;
$data["total"] = total_number_of_result
$data["per_page"] = 10;
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = "<div class = 'pagination'>";
$config['full_tag_close'] = "</div>";
//$config['additional_param'] = 'serialize_form()';
$config['div'] = '#div_to_load_result'; /* Here #content is the CSS selector for target DIV */
//$config['js_rebind'] = "alert('it works !!'); "; /* if you want to bind extra js code */
$this->load->library('table');
$this->jquery_pagination->initialize($config);
$data['html'] = $this->jquery_pagination->create_links().'<br>'.$this->table->generate($this->modelname->modelFunction());
$this->theme->view(path_of_view, $data);
}
// now in view add following line
<div id="mygrid"><?php echo $html; ?></div>https://stackoverflow.com/questions/6803744
复制相似问题