Codeigniter中的AJAX分页
AJAX Pagination in Codeigniter
是否可以在Codeigniter中使用AJAX分页而不编辑分页库?编辑分页库会使工作变得更容易吗?
您不需要编辑分页库。AJAX都是前端的,兄弟。您只需创建一个显示结果列表的视图,并创建另一个包含将用列表视图填充的div的视图。在结果容器中,可以使用另一个视图将ajax响应加载到div中。
使用Jquery插件分页
在加载视图前添加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>
相关文章:
- 使用ajax的服务器端分页&jQuery
- 分页:如何用AJAX加载第一个页面
- 导轨 4.宝石will_paginate.更改在 ajax 请求上设置的分页链接
- CodeIgniter - AJAX 生成的元素内的 AJAX 分页
- 分页-标准php或不使用ajax重新加载页面
- 在ajax分页视图(cakephp)中显示adsense的问题
- 在部分视图内渲染的WebGrid将引发“;“jQuery未定义”,当尝试执行基于ajax的分页或过滤时
- 在第三次onPageClick事件后,使用twbspagination插件和AJAX更新JS分页
- ajax请求上的kendo分页问题
- 如何使用CodeIgniter在Ajax中对数组进行切片以进行分页
- AJAX 分页,页面不可单击
- Ajax 分页链接自定义
- 使用 Ajax 分页时缺少元素(Facebook 赞按钮)
- Ajax 和 PHP 重新加载分页时无法弄清楚
- 在 AJAX 分页中添加类“活动”
- 分页如何正确生成数据表(ajax,服务器端)
- 使用服务器端分页链接进行 ajax 无限滚动
- 以 php 为单位进行分页.AJAX,PHP,MYSQL
- 分页AJAX,需要包括js所有的时间
- 分页Ajax在Rails中工作不一致