2011-05-11 21 views
1

我不知道我要問什麼是可能的或沒有..我想可能不是,但我想我會問無論如何。代碼點火器分頁與排序選項

有什麼方法可以重置分頁?

我有一個頁面上有分頁和排序選項。一切工作正常,但當排序選項之一更改,我想發送用戶回到第一頁。

(我敢肯定,我這樣做的方式是不是在所有,如果您有任何改進建議,請隨時得到我想要這樣的結果的最佳方式。)

 $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 for pagination 
$config['full_tag_open'] = '<div id="pagination" style= "clear:both;">'; 
$config['full_tag_close'] = '</div>'; 

//Initialise pagination 
$this->pagination->initialize($config); 
+0

您使用一個表來在頁面上顯示的數據? – Shivaas

+0

不,我不是我只是循環瀏覽每個結果並將它們回顯到頁面。 – flyersun

+0

我建議在一個表格中顯示數據(使用css樣式,它甚至不會像最終用戶的表格一樣!),然後利用jQuery dataTables插件進行排序,搜索和分頁。該插件支持服務器端分頁,因此您的代碼在某種程度上仍然可以重用。 – Shivaas

回答

3

你可以在控制器中保留一個默認排序,它不會在url中顯示,排序不會回到第一頁。

樣本

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'); 
}