Welcome Guest, Not a member yet? Register   Sign In
Implementing Search option in jqgrid by CI
#2

[eluser]Mizanur Islam Laskar[/eluser]
My Partial Controller
Code:
function list_all ()
        {
            $page  = isset($_POST['page'])?$_POST['page']:1; // get the requested page
            $limit = isset($_POST['rows'])?$_POST['rows']:10; // get how many rows we want to have into the grid
            $sidx  = isset($_POST['sidx'])?$_POST['sidx']:'id'; // get index row - i.e. user click to sort
            $sord  = isset($_POST['sord'])?$_POST['sord']:''; // get the direction
        
            if(!$sidx) $sidx =1;
            
            $count = $this->city_model->num_of_cities('');
        
            if( $count > 0 ) {
                $total_pages = ceil($count/$limit);    //calculating total number of pages
            } else {
                $total_pages = 0;
            }
            if ($page > $total_pages) $page=$total_pages;
        
            $start = $limit*$page - $limit; // do not put $limit*($page - 1)
            $start = ($start<0)?0:$start;  // make sure that $start is not a negative value
        
            $result = $this->city_model->sort_cities($sidx,$sord,$start,$limit,'');
            
        
            if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
                header("Content-type: application/xhtml+xml;charset=utf-8");
            } else {
                header("Content-type: text/xml;charset=utf-8");
            }
            $et = ">";
        
            echo "&lt;?xml version='1.0' encoding='utf-8'?$et\n";
            echo "<rows>";
            echo "<page>".$page."</page>";
            echo "<total>".$total_pages."</total>";
            echo "<records>".$count."</records>";
            // be sure to put text data in CDATA
            foreach($result as $row) {
                echo "<row id='".$row->id."'>";
                echo "<cell>&lt;![CDATA[".$row->id."]]></cell>";
                echo "<cell>&lt;![CDATA[".$row->name."]]></cell>";
                echo "<cell>&lt;![CDATA[".$row->country_code."]]></cell>";
                echo "<cell>&lt;![CDATA[".$row->district."]]></cell>";
                echo "<cell>&lt;![CDATA[".$row->population."]]></cell>";
                echo "<cell></cell>";
                echo "</row>";
            }
            echo "</rows>";
    
        }        
        
        function edit_test_save()
            {
                switch($_POST['oper'])
                    {
                        case('add'):
                            $insert_date['id']           = '';
                            $insert_date['name']         = $_POST['name'];
                            $insert_date['country_code'] = $_POST['country_code'];
                            $insert_date['district']     = $_POST['district'];
                            $insert_date['population']   = $_POST['population'];
                                                
                            $r = $this->common_model->add_data('city',$insert_date);
                            echo $r;
                            
                        break;
                        
                        case('edit'):
                        
                            $updated_data = array(
                                            'name'          => $_POST['name'],
                                            'country_code'  => $_POST['country_code'],
                                            'district'      => $_POST['district'],
                                            'population'    => $_POST['population']
                                          );
                            $r = $this->common_model->update_data('id', $_POST['id'], 'city', $updated_data);                      
                            echo $r;
                        
                        break;
                        
                        case('del'):
                        
                            $r = $this->common_model->delete_data('id', $_POST['id'], 'city');                      
                            echo $r;
                        
                        break;    
                            
                    }// end switch
            }

My Partial Model
Code:
function num_of_cities($wh)
        {
            if( !empty($wh) )
                {
                    $query = $this->db->query("SELECT * FROM city ".$wh);  
                }
            else
                {
                    $this->db->select('*');
                    $this->db->from('city');
                    $query = $this->db->get();
                }
            return $query->num_rows();
        }
    
    function sort_cities($sidx,$sord,$start,$limit,$wh)
        {
            if( !empty($wh) )
                {
                    $query = $this->db->query("SELECT * FROM city ".$wh." ORDER BY ".$sidx." ".$sord." LIMIT ".$start.", ".$limit."");  
                }
            else
                {
                    $this->db->select('*');
                    $this->db->from('city');
                    $this->db->order_by($sidx, $sord);
                    $this->db->limit($limit, $start);
                    $query = $this->db->get();
                }
            
            return $query->result();    
        }

Any idea please? Thanks is advance.


Messages In This Thread
Implementing Search option in jqgrid by CI - by El Forum - 06-11-2010, 11:15 PM
Implementing Search option in jqgrid by CI - by El Forum - 06-11-2010, 11:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB