简体   繁体   English

如何显示按钮[例如 查看,编辑,删除]在flexigrid中

[英]How to display buttons[eg. view,edit,delete] in flexigrid

I want the edit & view buttons to be displayed in the browser.I do not know what code should be modified to make the buttons come in the browser. 我希望在浏览器中显示编辑和查看按钮。我不知道应该修改什么代码才能使按钮出现在浏览器中。 I have linked the button helper but yet i do not know. 我已经链接了按钮帮助器,但是我不知道。 Do any one give any suggested modifications in my code as i am new to 'flexigrid'. 当我刚接触“ flexigrid”时,是否有人会对我的代码进行任何建议的修改。

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Plan extends MY_Controller {

function __construct()
{  
    parent::__construct();
    $this->load->helper('form');
    $this->load->library('form_validation');
    $this->load->model('plan_model');
    $this->template->add_js('js/default.js');
    $this->load->helper('buttons');
    $this->accessible(10,'v');
}
public function index($msg='')
{ 
    if($msg!='') 
        $data['msg']=$msg;
    else  
        $data['msg']='';
    $this->template->add_css('flexigrid/css/flexigrid.css');
    $this->template->add_js('flexigrid/flexigrid.js');

    $header = array(
                        array('display' => 'ID', 'name' => 'plan_id', 'width' => 50, 'sortable' => true, 'align' => 'center', 'hide' => true),
                        array('display' => 'Plans Name', 'name' => 'plan_name', 'width' => 120, 'sortable' => true, 'align' => 'left'),
                        array('display' => 'Validity (years)', 'name' => 'def_sub_years', 'width' => 120, 'sortable' => true, 'align' => 'left'),
                        array('display' => 'Plan Amount', 'name' => 'plan_amount', 'width' => 100, 'sortable' => true, 'align' => 'left'),
                        array('display' => 'Action', 'name' => 'action', 'width' => 150, 'align' => 'left')
                    );
    $colModel = json_encode($header);

    $action = array();

    $buttons = str_replace(array('"^','^"'),'',json_encode($action));

    $filter = array (
                        array('display' => 'Plan Name', 'name' => 'entity_name', 'isdefault' => true),
                        );
    $searchitems = json_encode($filter);

    $properties = array (
                            'url'               =>  base_url()."index.php/plan/get_plan",
                            'colModel'          =>  $colModel,
                            'buttons'           =>  $buttons,
                            'searchitems'       =>  $searchitems,
                            'sortname'          =>  "id",
                            'sortorder'         =>  "asc",
                            'title'             =>  "Plans",
                            'usepager'          =>  true,
                            'useRp'             =>  true,
                            'rp'                =>  10,
                            'showTableToggleBtn'=>  true,
                            'width'             =>  "auto",
                            'height'            =>  "auto"
                        );

    /*Flexigrid helper for grid view.*/
    $this->load->helper('flexigrid');
    $data['flexigrid'] = flexigrid("tbl_plan",$properties);
    $this->template->add_js($data['flexigrid'] , 'embed');
    $data['title'] = 'Plans';
    $this->template->write_view('content', 'plan/index', $data);
    $this->template->render();
}
function get_plan()
{   
    $action_data = array();
    $access_data = array();

    $data['page']       = $this->input->post('page');
    $data['rp']         = $this->input->post('rp');
    $data['sortname']   = $this->input->post('sortname');
    $data['sortorder']  = $this->input->post('sortorder');
    $data['query']      = $this->input->post('query');
    $data['qtype']      = $this->input->post('qtype');

    $result = $this->plan_model->get_plan($data);
    $field = array(0=>'id',1=>'plan_name',2=>'def_sub_years',3=>'plan_amount');
    $total = $result['total'];
    unset($result['total']);
    foreach($result as $rslt)
    { 
        /* if($rslt['id'] ==  ($this->settings_model->org_admin()))

        {*/
            $action_data[$rslt['id']] = array('view' => 'plan/edit_plan/','edit' => 'plan/edit_plan/','delete' => '');
            $access_data[$rslt['id']] = array('view' => $this->has_access(10,'v'),'edit' => $this->has_access(10,'m'),'delete' => '');
        //}
    }
    echo $this->settings_model->json_format($result,$field,$action_data,$access_data,$total,false,$data['page']);
}
function edit_plan($id,$action)
{
    $this->accessible(10,$action);
    $data['flag'] = 0;
    $data['plan_id'] = $id;

    if($data['plan_id'] == 0)   
         $data['plan_info']   = array('id'=>0,'plan_name'=>NULL,'def_sub_years'=>NULL,'plan_amount'=>NULL,'action'=>$action);
    else
    {
        $data['plan_info']   = $this->plan_model->plan_info($data['plan_id']);
        $data['plan_info']['action'] = $action;
    }

    $data['title'] = 'Plan';
    $this->template->write_view('content', 'plan/edit', $data);
    $this->template->render();
}

}
?>

从代码中,我们将id,plan_name,def_sub_years和action传递给$ field变量,因此我们必须添加4 =>'action'将使按钮显示在浏览器中。

 $field = array(0=>'id',1=>'plan_name',2=>'def_sub_years',3=>'plan_amount',4=>'action');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM