Welcome Guest, Not a member yet? Register   Sign In
Jqgrid pagination question?
#1

[eluser]cestaz18[/eluser]
Please help me...
i have a problem in pagination in jqgrid..

the calculation of total rows of all page...
my problem is the total rows count only per page????

Example:
i have 13 rows of data

my rowlist is [10,20,30]

when i choose in dropdown list of rows 10

in page one i have 10 rows the total rows show in the right hand shows like this
view 1-10 of 10

and when i next it to page 2

it shows....

view 11-13 of 3

it seems like it count the number of rows per page...

i want it to show the total numbers of rows or items in all pages..

example:

in the given data i show to you..

i like it to be shown..

in page 1
view 1-10 of 13

and in page 2 view 11-13 of 13

here's my code..

please help me..thanks

-cess-^^



Code:
$page = $this->input->post('page');
        $limit = $this->input->post('rows'); // get how many rows we want to have into the grid
        $sidx = $this->input->post('sidx'); // get index row - i.e. user click to sort
        $sord = $this->input->post('sord'); // get the direction
        
        $query = $this->input->post('query');
        $qtype = $this->input->post('qtype');
        
        if (!$sidx) $sidx = 1;
        if (!$sord) $sord = 'asc';
                
        if (!$page) $page = 1;
        if (!$limit) $limit = 25;
    
        $this->db->start_cache();
        
        if ($qtype == 'role_code' && $query) $this->db->like('role_code', $query);
        if ($qtype == 'role_code' && $query) $this->db->like('role_desc', $query);
        
        // calculate the number of rows for the query. We need this for paging the result
        $this->db->from('sec_role');
        $this->db->where('sec_role.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("role_id as pkey,role_id, role_code, role_desc");
        $this->db->order_by($sidx,$sord);
        $this->db->limit($limit, $start);
        $query = $this->db->get("sec_role");
        
        $this->db->flush_cache();
        
        $data['db'] = $query;
        $data['page'] = $page;
        $data['num'] = $num;
        return $data;
#2

[eluser]saidai jagan[/eluser]
I think there is 3 threads with the same problem (Same code also). :cheese:
#3

[eluser]cestaz18[/eluser]
[quote author="saidai jagan" date="1262870028"]I think there is 3 threads with the same problem (Same code also). :cheese:[/quote]

yes and i see your posted code but it doesnt work on me..help please..
#4

[eluser]cestaz18[/eluser]
thank you to those who help me in this pagination problem..

but thank God i found now the answer..hehe^^

and it works..

here's my code

VIEW
Code:
<div id="List" class="panel" style="display:block">


    <div class="content">
            <div class="dpane">
                   <table id="listFlex" class="listFlex" cellpadding="0" cellspacing="0"></table>
                    <div id="pager2" class="scroll" style="text-align: center;"></div>

            </div>
    </div>
</div>


Application/views/template -- TABLE.php

Code:
&lt;?
$this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
$this->output->set_header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
$this->output->set_header("Cache-Control: no-cache, must-revalidate" );
$this->output->set_header("Pragma: no-cache" );
$this->output->set_header("Content-type: text/x-json");

$json = "";
$json .= "{\n";
$json .= "page: $page,\n";
$json .= "total: $totalpages,\n";
$json .= "records:  $totalrecords,\n";
$json .= "rows: ";
$rows = array();
if (isset($db)) {
    
    foreach($db->result_array() as $row):
    
    $key = key($row);
    $id = $row[$key];
    unset($row[$key]);
    $cell = array();
        foreach ($row as $item)
            {
                $cell[] = $item;                
            }
    $rows[] = array(
    
        "id" => $id,
        "cell" => $cell
        );
        
    endforeach;
    
}

$json .= json_encode($rows);




if (isset($moredata))
    $json .= ",".json_encode(array('moredata'=>$moredata));
$json .= "\n";
$json .= "}";
echo $json;
?&gt;



CONTROLLER
Code:
function listview()
    {
        $data = $this->Sec_role_db->getList();    
        $this->load->view('template/table',$data);
    }


MODEL
Code:
function getList()
    {
        $page = $this->input->post('page');
        $limit = $this->input->post('rows'); // get how many rows we want to have into the grid
        $sidx = $this->input->post('sidx'); // get index row - i.e. user click to sort
        $sord = $this->input->post('sord'); // get the direction
        
        $query = $this->input->post('query');
        $qtype = $this->input->post('qtype');
        
        if (!$sidx) $sidx = 'role_id';
        if (!$sord) $sord = 'asc';
                
        if (!$page) $page = 1;
        if (!$limit) $limit = 25;
        
        //$start = (($page-1) * $limit);
        
        $this->db->start_cache();
        
        if ($qtype == 'role_code' && $query) $this->db->like('role_code', $query);
        if ($qtype == 'role_code' && $query) $this->db->like('role_desc', $query);
        
        // calculate the number of rows for the query. We need this for paging the result
        $this->db->from('sec_role');
        $this->db->where('sec_role.is_deleted','0');
        $count = $this->db->count_all_results(); //code added by cess
        //$row = $this->db->count_all_results(); //code added by cess
        //$count = $row['count'];
        
        // calculate the total pages for the query - code added by cess
        if( $count > 0 && $limit > 0) {
              $total_pages = ceil($count/$limit);
        } else {
              $total_pages = 0;
        }
        
        // if for some reasons the requested page is greater than the total
        // set the requested page to total page - code added by cess
        if ($page > $total_pages) $page=$total_pages;
        
        // 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("role_id as pkey,role_id, role_code, role_desc");
        $this->db->order_by($sidx,$sord);
        $this->db->limit($limit, $start);
        $query = $this->db->get("sec_role");
        
        $this->db->flush_cache();
        
        $data['db'] = $query;
        $data['page'] = $page;
        $data['totalpages'] = $total_pages;//code added by cess^^
        $data['totalrecords']=$count; //- code added by cess
            
        return $data;    
    }




Theme © iAndrew 2016 - Forum software by © MyBB