Welcome Guest, Not a member yet? Register   Sign In
[SOLVED!!!]paging error
#1

[eluser]maria clara[/eluser]
hi to all,

im having a problem with the pagination of the jqgrid.
the total number of pages should be acquired. but its just computing the total number of items and was placed in the place where the total number of pages should be in.

in short,they interchanged their positions.
here is the code i used in the MODEL:
Code:
$page = $this->input->post('page');

if (!$page) $page = 1;
if (!$limit) $limit = 25;
        
$start = (($page-1) * $limit);

$this->db->limit($limit, $start);

$num = $this->db->count_all_results();

$data['page'] = $page;
$data['num'] = $num;
return $data;

here is the file for you to see what i mean.

hope someone could help me..

thanks in advance,
maria
#2

[eluser]brianw1975[/eluser]
Maria, I'm willing to put dollars to donuts that you have $page and $num reversed in your *view* file.
#3

[eluser]maria clara[/eluser]
[quote author="brianw1975" date="1262854673"]Maria, I'm willing to put dollars to donuts that you have $page and $num reversed in your *view* file.[/quote]

please elaborate what you mean...
it keeps on getting the total numbers of rows per page. but it should be the total number of items in the whole grid..

here is the controller:

Code:
if (!$page) $page = 1;
        if (!$limit) $limit = 25;
        
        $start = (($page-1) * $limit);
    
        $this->db->start_cache();
        
        if ($qtype == 'user_id' && $query) $this->db->like('user_id', $query);
        if ($qtype == 'username' && $query) $this->db->like('username', $query);
        
        $this->db->join('maint_department erp_c','sec_users.dept_id=c.dept_id','left');        
        $this->db->join('sec_role erp_d','sec_users.role_id=d.role_id','left');    
        $this->db->from('sec_users');
        //$this->db->where('sec_users.is_deleted','0');
        $num = $this->db->count_all_results();
            
        $this->db->select("user_id as pkey, username, last_name, first_name, middle_initial, d.role_id, c.dept_id");
        $this->db->order_by($sidx,$sord);
        $this->db->limit($limit, $start);
        $query = $this->db->get("sec_users");
        
        $this->db->flush_cache();
        
        $data['db'] = $query;
        $data['page'] = $page;
        $data['num'] = $num;
        return $data;

hope you could help me..

thanks,
maria
#4

[eluser]brianw1975[/eluser]
with the disclaimer that I have no intimate knowledge of your full code take the following response in a theoretical frame of mind:

ok, your model there is returning the $data array to the controller, the controller is doing one of two things, processing that data into a more formal format (i.e JSON ) or b) passing that info to a view/template file which is then sent to the browser.

I'm willing to bet that you have the 'num' and 'page' reversed in *that* file the one actually creates the string being sent to the browser.

ie you have
Code:
$numcount = $data['page'];
$rowcount = $data['num'];

echo createOutputString($numcount,$rowcout);

instead of

Code:
$numcount = $data['num'];
$rowcount = $data['page'];

echo createOutputString($numcount,$rowcout);

Of course the problem *could* be that the Javascript on the other end is doing something along the same lines (the vars are in the wrong places with each other)
#5

[eluser]maria clara[/eluser]
i tried to interchange
Code:
$data['page'] = $page;
$data['num'] = $num;

with:
Code:
$data['num'] = $num;
$data['page'] = $page;

but still it doesn't work.

what i mean is that i have this 11 items added. and you can view only 10 per page, that means i have 2 pages. but instead of having this:

Quote://noteSadyou can view only 10 per page)

view 1-10 of 11 in a page

it shows this:
Quote:view 1-10 of 10 in the 1st page

and

view 11-11 of 1 in the 2nd page

i now have this code:
Code:
if (!$page) $page = 1;
        if (!$limit) $limit = 25;
        
        $start = (($page-1) * $limit);
    
        $this->db->start_cache();
        
        if ($qtype == 'user_id' && $query) $this->db->like('user_id', $query);
        if ($qtype == 'username' && $query) $this->db->like('username', $query);
        
        // calculate the number of rows for the query. We need this for paging the result
        $this->db->join('maint_department erp_c','sec_users.dept_id=c.dept_id','left');        
        $this->db->join('sec_role erp_d','sec_users.role_id=d.role_id','left');    
        $this->db->from('sec_users');
        //$this->db->where('sec_users.is_deleted','0');
        $num = $this->db->count_all_results();
        
        // calculate the total pages for the query
        if( $num > 0 && $limit > 0) {
              $num = ceil($num/$limit);
        } else {
              $num = 0;
        }
        
        // if for some reasons the requested page is greater than the total
        // set the requested page to total page
        if ($page > $num) $page=$num;
        
        // calculate the starting position of the rows
        $start = $limit * $page - $limit; // do not put $limit*($page - 1)
        
        // if for some reasons start position is negative set it to 0
        // typical case is that the user type 0 for the requested page
        if($start <0) $start = 0;
            
        $this->db->select("user_id as pkey, username, last_name, first_name, middle_initial, d.role_id, c.dept_id");
        $this->db->order_by($sidx,$sord);
        $this->db->limit($limit, $start);
        $query = $this->db->get("sec_users");
        
        $this->db->flush_cache();
        
        $data['db'] = $query;
        $data['page'] = $page;
        $data['num'] = $num;
        return $data;

thanks,
maria




Theme © iAndrew 2016 - Forum software by © MyBB