sorting - code igniter pagination with sort options -
i'm not sure if i'm ask possible or not.. i'm thinking not thought ask anyways.
is there way reset pagination?
i've got page has pagination , sort option on it. works fine when 1 of sort options changed send user first page.
(i'm pretty sure way i'm doing isn't @ best way result want if have suggestions improvements please feel free.)
$array = explode ("_",$this->uri->segment(4)); if(count($array) > 1){ $search_id = $array[1]; $start = $this->uri->segment(5); $uri_segment = 5; }else{ $start = $this->uri->segment(4); $uri_segment = 4; $search_id = null; } $config['per_page'] = $this->settings['products_per_page']; $config['total_rows'] = $this->categories_model->get_num_rows($cat_id , $search_type, $search_data); $query = $this->categories_model->get_category_pages($cat_id, $new_limit, $new_sort, $search_id, $start, $this->settings['category_order'], $search_type, $search_data, $config['total_rows'])) $config['base_url'] = base_url() . 'index.php/categories/view/' . $cat_id ."/" . $search_string ; $config['uri_segment'] = $uri_segment; //congig settings pagination $config['full_tag_open'] = '<div id="pagination" style= "clear:both;">'; $config['full_tag_close'] = '</div>'; //initialise pagination $this->pagination->initialize($config);
you may keep default sorting in controller not show in url.so sorting not first page.
a sample
class post extends jewelery_controller { public function __construct() { parent::__construct(); $this->load->model('prime_model'); } public function index($ordr_by = 'post_title', $sortr = 'asc') { if ($this->uri->segment(6)) { $data['segment'] = $this->uri->segment(6); } else { $data['segment'] = 0; } if ($this->uri->segment(4)) { $ordr_by = $this->uri->segment(4); } if ($this->uri->segment(5)) { $sortr = $this->uri->segment(5); } $data['title'] = 'all posts'; $this->load->library('pagination'); $config['base_url'] = base_url() . 'admin/post/index/' . $ordr_by . '/' . $sortr; $config['full_tag_open'] = '<div class="pagination"><ul>'; $config['full_tag_close'] = '</ul></div>'; $config['cur_tag_open'] = '<li class="active"><a href="">'; $config['cur_tag_close'] = '</a></li>'; $config['prev_tag_open'] = '<li>'; $config['prev_tag_close'] = '</li>'; $config['next_tag_open'] = '<li>'; $config['next_tag_close'] = '</li>'; $config['num_tag_open'] = '<li>'; $config['num_tag_close'] = '</li>'; $config['uri_segment'] = 6; $config['total_rows'] = $this->db->get('jewel_posts')->num_rows(); $config['per_page'] = 10; $this->pagination->initialize($config); $data['post_info'] = $this->prime_model->master_join('jewel_posts', 'jewel_jewelry_type', 'jewel_posts.jewelry_type = jewel_jewelry_type.jewelry_type_id', 'left', false, false, false, false, false, false, false, false, $ordr_by, $sortr, $config['per_page'], $data['segment']); $this->load->view('admin/header', $data); $this->load->view('admin/post/index'); $this->load->view('admin/footer'); }
Comments
Post a Comment