CodeIgniter Forums

Full Version: SOLVED:[help]Jqgrid master detail list in another page!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]cestaz18[/eluser]
i have master detail table list in another page...

the problem is i can't show the data output inside the table...

help please...

here's my code

VIEW

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


.....

  <div class="dpane">
        <table id="detFlex1" class="detFlex"></table>
    <div id="pager2" class="scroll" style="text-align: center;"></div>                      
                    </div>


SCRIPT


Code:
$(".listFlex").jqGrid({
         url: root + mod + '/listview',
          editurl: root + mod + '/post',        
          sortable: true,
         datatype: "json",
         mtype: 'POST',
         colNames:['','Username','Lastname', 'Firstname','Middle Initial'],
         colModel:[
                       {name:'user_id', index: 'item', hidden: true},
                      {name:'username',index:'username', width:80, align:"left", editable:true},
                    {name:'last_name', index: 'last_name', width:80, editable: true},
                       {name:'first_name',index:'first_name', width:100,align:"left",editable:true},
                    {name:'middle_initial', index: 'middle_initial', width:80, editable: true}
                    
               ],
         rowNum:10,
         rowList:[10,20,30],
         rownumbers: true,
         pager: '#pager',
         sortname: 'username',
         viewrecords: true,
         sortorder: 'asc',
         autowidth: true,
                  ondblClickRow: function (celDiv,id)
                        {
                            //alert (id);
                            $(celDiv).addClass("pointer");
                            $(celDiv).click(function(){
                                $('.toolbar a[title=Header]').trigger('click');                
                                viewdb(id);        
                            });
                        },
         height: "200",
         caption:"User Role List -Dean",
onSelectRow: function(rowid, selected)
            {
                if(rowid != null) {
                    //jQuery("#detFlex1").jqGrid('setGridParam',{postData:{user_id:rowid}});
                     jQuery("#detFlex1").setGridParam({url: root + mod + '/detaillistview',page:1})
                     .setCaption("Detail: "+rowid)
                    jQuery("#detFlex1").trigger("reloadGrid");
                    $('.toolbar a[title=Header]').trigger('click');                
                    viewdb(rowid);        
                    //viewHeader(rowid, selected);
                }
            }
            
            
        
            
});


$("#detFlex1").jqGrid({
         url: root + mod + '/detaillistview',
         datatype: "json",
         mtype: 'POST',
         colNames:['','Company Code','Company Name', ''],
         colModel:[
                   {name:'company_access_id', index: 'company_access_id', hidden: true},
                      {name:'company_code',index:'company_code', width:200, align:"left", editable:true},
                    {name:'company_name', index: 'company_name', width:250, editable: true},
                   {name:'company_id',index:'company_id', hidden: true}
               ],
         rowNum:10,
         rowList:[10,20,30],
         rownumbers: true,
         pager: '#pager2',
         sortname: 'company_code',
         viewrecords: true,
         sortorder: 'asc',
         autowidth: true,
         height: "100",
         caption:"Details"

});

El Forum

[eluser]cestaz18[/eluser]
CONTROLLER

Code:
function post()
    {
        $c = "";    
        $data['action'] = $this->input->post('action');    
        $item = $this->input->post('item');        
        if ($data['action']=='view')
        {

            $dt['user_id'] = $this->input->post('item');
            $details = $this->User->getDetails($dt);

            if ($details)
            {
                $data['db'] = array('item'=>$dt['user_id'],
                                    'username'=>$details['username'],    
                                    'last_name'=>$details['last_name'],                                    
                                    'first_name'=>$details['first_name'],
                                    'middle_initial'=>$details['middle_initial'],
                                    'role_id'=>$details['role_id'],                                    
                                    'role_code'=>$details['role_code'],
                                    'role_desc'=>$details['role_desc'],                                        
                                    'dept_id'=>$details['dept_id'],                                    
                                    'dept_code'=>$details['dept_code'],
                                    'dept_desc'=>$details['dept_desc']
                            
                                                                
                                    //'a.first_name'=>$details['a.first_name'],
                                    //'a.middle_initial'=>$details['a.middle_initial']                                    
                                    );
                $data['count'] = $this->User->countDetailList($dt);                                    
                #$data['count'] = 0;
            }
    
            $data['response'] = $c;
            $json['json'] = $data;            
            $this->load->vars($data);
            $this->load->view('template/ajax',$json);    
        }
        
        //language
        elseif ($data['action']=="language")
        {
            $lang_select =  $this->input->post('language');
            $this->lang->load('login', $lang_select);//login(module) & lang_select(language)
            $data['dt'] = array('h1'=>lang('h1'),
                                'instruction'=>lang('instruction'),
                                'login'=>lang('login'),
                                'pass'=>lang('pass'),
                                'company'=>lang('company'),
                                'lang_select'=>lang('language'),
                                'remember'=>lang('rememberme'),
                                'log'=>lang('log'),
                                'forgot'=>lang('forgot'),
                                'get_pass'=>lang('get_pass'),
                                'instruction2'=>lang('instruction2'),
                                'username2'=>lang('username2'),
                                'email'=>lang('email'),
                                'get'=>lang('get'),
                                'irmp'=>lang('irmp'),
                                'js'=>lang('js'));    
                                          
            $data['response'] = $c;
            $data['action'] = 'language';
            
            $json['json'] = $data;
            
        }
        
        elseif ($data['action']=='save')
        {...


function listview()
    {
        $data = $this->User->getList();    
        $this->load->view('template/table',$data);
    }
    
//----------------------------------------------------------------------------
    function detaillistview()
    {
        $data = $this->User->getDetailList();    
        $this->load->view('template/table',$data);
    }

El Forum

[eluser]cestaz18[/eluser]
MODEL

Code:
function getDetailList() //Show the list of registered user with company details
    {
          
        
        $item = $this->input->post("item");
        //print_r($_POST);
        
        $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
        //$id =$this->input->post('id');

    /*    if (!$sortname) $sortname = 'sec_companyaccess.user_id';
        if (!$sortorder) $sortorder = 'DESC';*/
        
        if (!$sidx) $sidx = 'sec_companyaccess.user_id'; // if we not pass at first time index use the first column for the index
        if (!$sord) $sord = 'desc';    
        
        
        //$page = 1;
        
        if (!$page) $page = 1;
        if (!$limit) $limit = 25;
        
        $start = (($page-1) * $limit);
        
        $this->db->start_cache();
        
/*        if(isset ($_REQUEST["sec_companyaccess.user_id"]))
            $rowid = $_REQUEST["sec_companyaccess.user_id"];
        else
            $rowid = "";*/




        $this->db->join('maint_company','sec_companyaccess.company_id=maint_company.company_id','left');
        $this->db->join('sec_users ','sec_companyaccess.user_id=sec_users.user_id','left');
        $item = $this->input->post('sec_users.user.id');
        $this->db->from('sec_companyaccess');
        //$this->db->where("sec_companyaccess.user_id", 1);
        $this->db->where("sec_companyaccess.user_id", $item);
        //$this->db->where("sec_companyaccess.user_id", $id);
        $count = $this->db->count_all_results(); //code added by cess
    
        
        // 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("sec_companyaccess.company_access_id as pkey,sec_companyaccess.company_access_id, maint_company.company_code, maint_company.company_name,sec_companyaccess.company_id ");
        
        $this->db->order_by($sidx,$sord);
        
        //$this->db->limit($rp, $start);
        $query = $this->db->get("sec_companyaccess");
/*        $sql = ("SELECT erp_sec_companyaccess.company_access_id as pkey,erp_sec_companyaccess.company_access_id, erp_maint_company.company_code, erp_maint_company.company_name,erp_sec_companyaccess.company_id                
        FROM erp_sec_companyaccess
        INNER JOIN erp_sec_users
        ON erp_sec_companyaccess.user_id= erp_sec_users.user_id
        LEFT JOIN erp_maint_company
        ON erp_sec_companyaccess.company_id=erp_maint_company.company_id
        WHERE erp_sec_companyaccess.user_id= erp_sec_users.user_id");
        $query = $this->db->query($sql);
        $num = $this->db->count_all_results();*/
        $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;            


    }

El Forum

[eluser]cestaz18[/eluser]
Master-Detail jqGrid

this is the solution after 1000 years thinking and dreaming of code...hehehe^^


VIEW (home.php)

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

<div class="dpane">
                           <table id="detFlex1" class="detFlex"></table>
                        <div id="pager2" class="scroll" style="text-align: center;"></div>                      
                    </div>

VIEW (script.js)

Code:
$(".listFlex").jqGrid({
         url: root + mod + '/listview',
          editurl: root + mod + '/post',        
          sortable: true,
         datatype: "json",
         mtype: 'POST',
         colNames:['','Username','Lastname', 'Firstname','Middle Initial'],
         colModel:[
                       {name:'user_id', index: 'item', hidden: true},
                      {name:'username',index:'username', width:80, align:"left", editable:true},
                    {name:'last_name', index: 'last_name', width:80, editable: true},
                       {name:'first_name',index:'first_name', width:100,align:"left",editable:true},
                    {name:'middle_initial', index: 'middle_initial', width:80, editable: true}
                    
               ],
         rowNum:10,
         rowList:[10,20,30],
         rownumbers: true,
         pager: '#pager',
         sortname: 'username',
         viewrecords: true,
         sortorder: 'asc',
         autowidth: true,

                 height: "200",
         caption:"User Role List -Dean",
onSelectRow: function(ids) {
    if(ids == null) {
        ids=0;
        if(jQuery("#detFlex1").jqGrid('getGridParam','records') >0 )
        {
            jQuery("#detFlex1").jqGrid('setGridParam',{url:root + mod + '/detaillistview/' + ids,page:1});
            jQuery("#detFlex1").jqGrid('setCaption',"Detail: "+ids)
            .trigger('reloadGrid');
            $('.toolbar a[title=Header]').trigger('click');                
            viewdb(ids);
        }
    } else {
        jQuery("#detFlex1").jqGrid('setGridParam',{url:root + mod + '/detaillistview/' + ids,page:1});
        jQuery("#detFlex1").jqGrid('setCaption',"Detail: "+ids)
        .trigger('reloadGrid');
        $('.toolbar a[title=Header]').trigger('click');                
        viewdb(ids);
        }
    }
});


$("#detFlex1").jqGrid({
         url: root + mod + '/detaillistview',
         datatype: "json",
         mtype: 'POST',
         colNames:['','Company Code','Company Name', ''],
         colModel:[
                   {name:'company_access_id', index: 'company_access_id', hidden: true},
                      {name:'company_code',index:'company_code', width:200, align:"left", editable:true},
                    {name:'company_name', index: 'company_name', width:250, editable: true},
                   {name:'company_id',index:'company_id', hidden: true}
               ],
         rowNum:10,
         rowList:[10,20,30],
         rownumbers: true,
         pager: '#pager2',
         sortname: 'company_code',
         viewrecords: true,
         sortorder: 'asc',
         autowidth: true,
         height: "100",
         caption:"Details"

        }
);

El Forum

[eluser]cestaz18[/eluser]
CONTROLLER (sec_users.php)

Code:
function post()
    {
        $c = "";    
        $data['action'] = $this->input->post('action');    
        $item = $this->input->post('item');    
        
        if ($data['action']=='view')
        {

            $dt['user_id'] = $this->input->post('item');
            $details = $this->User->getDetails($dt);

            if ($details)
            {
                $data['db'] = array('item'=>$dt['user_id'],
                                    'username'=>$details['username'],    
                                    'last_name'=>$details['last_name'],                                    
                                    'first_name'=>$details['first_name'],
                                    'middle_initial'=>$details['middle_initial'],
                                    'role_id'=>$details['role_id'],                                    
                                    'role_code'=>$details['role_code'],
                                    'role_desc'=>$details['role_desc'],                                        
                                    'dept_id'=>$details['dept_id'],                                    
                                    'dept_code'=>$details['dept_code'],
                                    'dept_desc'=>$details['dept_desc']
                            
                                                                
                                    //'a.first_name'=>$details['a.first_name'],
                                    //'a.middle_initial'=>$details['a.middle_initial']                                    
                                    );
                $data['count'] = $this->User->countDetailList($dt);                                    
                #$data['count'] = 0;
            }
    
            $data['response'] = $c;
            $json['json'] = $data;            
            $this->load->vars($data);
            $this->load->view('template/ajax',$json);    
        }
        
        //language
        elseif ($data['action']=="language")
        {
            $lang_select =  $this->input->post('language');
            $this->lang->load('login', $lang_select);//login(module) & lang_select(language)
            $data['dt'] = array('h1'=>lang('h1'),
                                'instruction'=>lang('instruction'),
                                'login'=>lang('login'),
                                'pass'=>lang('pass'),
                                'company'=>lang('company'),
                                'lang_select'=>lang('language'),
                                'remember'=>lang('rememberme'),
                                'log'=>lang('log'),
                                'forgot'=>lang('forgot'),
                                'get_pass'=>lang('get_pass'),
                                'instruction2'=>lang('instruction2'),
                                'username2'=>lang('username2'),
                                'email'=>lang('email'),
                                'get'=>lang('get'),
                                'irmp'=>lang('irmp'),
                                'js'=>lang('js'));    
                                          
            $data['response'] = $c;
            $data['action'] = 'language';
            
            $json['json'] = $data;
            
        }
        
        elseif ($data['action']=='save')
        {
            $item = $this->input->post("item");    
            $dt['username'] = $this->input->post('username');
            $sec_exist = $this->User->getDetails($dt);
            
            if ($sec_exist && $item!=$sec_exist['user_id'])
            {
                $c .= 'User ID already exists.';
                $data['action'] = 'exist';
            }
            else
            {
                $fields = array(
                        "username"
                        ,"last_name"
                        ,"first_name"
                        ,"middle_initial"
                        ,"role_id"
                        ,"dept_id"                    
                        );
                
            foreach ($fields as $field)
            {
                if (isset($_POST[$field])) $dt[$field] = $this->input->post($field);
            }
            
            $item = $this->input->post("item");        
            
        /*    $data['item'] = $this->User->save($dt,$item);
            $company = $this->session->userdata('company');
            $dt['company_id'] = $company['company_id'];*/    
                    
            $rows = $this->input->post("row0");
            $data['item'] = $this->User->save($dt,$item,$rows);    
            
            $c .= lang('users_saved_item');                        
            }    
            $data['response'] = $c;
            
            
            $json['json'] = $data;
        }
        
        elseif ($data['action']=='delete')
        {
            $dt['user_id'] = $this->input->post("item");    
            $dt['username'] = $this->input->post("username");    
            $data['deleted_row'] = $this->User->delete($dt);
            
            $c .= lang('users_deleted_item').$data['deleted_row'];
            $data['response'] = $c;
        
            $json['json'] = $data;    
        }

function listview()
    {
        $data = $this->User->getList();    
        $this->load->view('template/table',$data);
    }
    
//----------------------------------------------------------------------------
    function detaillistview()
    {
        $data = $this->User->getDetailList($this->uri->segment(3));    
        $this->load->view('template/table',$data);
    }

El Forum

[eluser]cestaz18[/eluser]
class Sec_users extends Controller {

function Sec_users()
{
parent::Controller();
$method = $this->uri->rsegment(2);//uri class segment or retrieve rsegment 2
$user = $this->session->userdata('user');//fetch 'user' to $user
if (($method!='login'&&$method!='auth'&&$method!='logout'&&$method!='post')&&!$user) redirect('sec_users/login');

$this->load->model('Dataset_db');
$this->load->model('Users_db','User');

#$lang_select = $this->input->post('language');
#$this->lang->load('login', $lang_select);

$lang_select = $this->session->userdata('lang_select');
$this->config->set_item('language', $lang_select);

$this->lang->load('language');//load language file for sec_users e.g sec_user_lang.php

$this->load->helper('url'); // add this to your function controller


}

El Forum

[eluser]cestaz18[/eluser]
MODEL (users_db.php)

Code:
function getDetailList($ids) //Show the list of registered user with company details
    {
          
        //$id = $this->input->post('rowid');
        
        //$item = $this->input->post('item');
        //print_r($_POST);
        $id = $this->input->post('ids');
        
        $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
        //$id =$this->input->post('id');

    /*    if (!$sortname) $sortname = 'sec_companyaccess.user_id';
        if (!$sortorder) $sortorder = 'DESC';*/
        
        if (!$sidx) $sidx = 'sec_companyaccess.user_id'; // if we not pass at first time index use the first column for the index
        if (!$sord) $sord = 'desc';    
        
        
        //$page = 1;
        
        if (!$page) $page = 1;
        if (!$limit) $limit = 25;
        
        $start = (($page-1) * $limit);
        
        $this->db->start_cache();
        
/*        if(isset ($_REQUEST["sec_companyaccess.user_id"]))
            $rowid = $_REQUEST["sec_companyaccess.user_id"];
        else
            $rowid = "";*/




        $this->db->join('maint_company','sec_companyaccess.company_id=maint_company.company_id','left');
        $this->db->join('sec_users ','sec_companyaccess.user_id=sec_users.user_id','left');
        //$item = $this->input->post('sec_users.user.id');
        $this->db->from('sec_companyaccess');
        //$this->db->where("sec_companyaccess.user_id", 1);
        //$this->db->where("sec_companyaccess.user_id", $item);
        $this->db->where("sec_companyaccess.user_id", $ids);
        $count = $this->db->count_all_results(); //code added by cess
    
        
        // 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("sec_companyaccess.company_access_id as pkey,sec_companyaccess.company_access_id, maint_company.company_code, maint_company.company_name,sec_companyaccess.company_id ");
        
        $this->db->order_by($sidx,$sord);
        
        //$this->db->limit($rp, $start);
        $query = $this->db->get("sec_companyaccess");
/*        $sql = ("SELECT erp_sec_companyaccess.company_access_id as pkey,erp_sec_companyaccess.company_access_id, erp_maint_company.company_code, erp_maint_company.company_name,erp_sec_companyaccess.company_id                
        FROM erp_sec_companyaccess
        INNER JOIN erp_sec_users
        ON erp_sec_companyaccess.user_id= erp_sec_users.user_id
        LEFT JOIN erp_maint_company
        ON erp_sec_companyaccess.company_id=erp_maint_company.company_id
        WHERE erp_sec_companyaccess.user_id= erp_sec_users.user_id");
        $query = $this->db->query($sql);
        $num = $this->db->count_all_results();*/
        $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;            


    }