jqgrid主从表查询+添加grid按钮+查询框的“X”取消+查询框去掉

来源:互联网 发布:淘宝人工云客服没有了 编辑:程序博客网 时间:2024/05/16 17:03
    public function maingrid(){
    // jqgrid查询
        Vendor('jqSuite.jqGrid');
        Vendor('jqSuite.jqGridPdo');
        $conn = new PDO(C('GRIDB.DSN'),C('GRIDB.USER'),C('GRIDB.PWD')); 
        $conn->query("SET NAMES utf8"); 
        $grid = new jqGridRender($conn); 
        // Write the SQL Query
        $sqlx = "SELECT a.org_id,a.org_no as user_name,a.org_name,a.phone,a.email,a.address,a.consume_money,a.balance";
        $sqlx .= " FROM ".C('DB_PREFIX')."tenants AS a ";
        // $sqlx .= " WHERE a.user_id = ".$this->user_id." AND a.org_id = ".$this->org_id;
          $grid->SelectCommand = $sqlx;
          // Set the table to where you update the data
        $grid->table = C('DB_PREFIX').'tenants';
        // Set output format to json 
        $grid->dataType = 'json'; 
        // Let the grid create the model 
        $grid->setColModel(); 
        // Set the url from where we obtain the data 
        $grid->setUrl('index.php?m=Member&a=maingrid'); 
        // Set some grid options 
        $grid->setGridOptions(array(
            "rowNum"=>15,
            "height"=>450,
            "gridview"=>false,
            "rowList"=>array(10,15,20,25,30),
            // "sortname"=>"user_id",
            "sortorder"=>"desc",
            "rownumbers"=>true,
            "autowidth"=>true,
        )); 
        $grid->addCol(array( 
            "name"=>"action", 
            "editable"=>false, 
            "sortable"=>false, 
            "resizable"=>false, 
            "fixed"=>true, 
            // "height"=>450,
            // "formatoptions"=>array("bSubmit"=>true) 
        ), "last");
        // $grid->setColProperty('org_id', array("label"=>"ID", "width"=>50));
        $grid->setColProperty('org_id', array("label"=>"id", "width"=>50));
        $grid->setColProperty('user_name', array("label"=>"用户名", "width"=>50));
        $grid->setColProperty('org_name', array("label"=>"公司名称", "width"=>50));
        $grid->setColProperty('phone', array("label"=>"电话", "width"=>50)); 
        $grid->setColProperty('email', array("label"=>"邮箱", "width"=>50)); 
        $grid->setColProperty('address', array("label"=>"地址", "width"=>50)); 
        $grid->setColProperty('consume_money', array("label"=>"消耗金额", "width"=>80)); 
        $grid->setColProperty('balance', array("label"=>"可用余额", "width"=>50)); 
        $grid->setColProperty('action', array("label"=>"操作", "width"=>250,"formatter"=>"js:actions",'align'=>'center'));
        $grid->setColProperty('action', array("label"=>"操作", "width"=>200,"formatter"=>"js:actions","search"=>false));
        $actions=<<<ACTION
        function actions(callValue,options,rowObject)
        {
            return '<button class="btn btn-success" onclick="check(this,\'reset\');">重置密码</button>&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-warning" onclick="check(this,\'recharge\');">充值</button>';
        }
ACTION;
        $grid->setJSCode($actions);
        // $grid->setGridEvent('onSelectRow', $selectorder); 
        // Enable navigator 
        $grid->toolbarfilter=true;
        $grid->setSubGridGrid("index.php?m=Member&a=subgrid");
        $grid->navigator = false; 
        // Enable only editing 
        $grid->setNavOptions('navigator', array("excel"=>false,"add"=>false,"edit"=>false,"del"=>false,"view"=>false));
        // Enjoy 
        $grid->renderGrid('#grid','#pager',true, null, null, true,true); 
        $conn = null; 
    }
    public function subgrid(){
        Vendor('jqSuite.jqGrid');
        Vendor('jqSuite.jqGridPdo');
        $conn = new PDO(C('GRIDB.DSN'),C('GRIDB.USER'),C('GRIDB.PWD')); 
        $conn->query("SET NAMES utf8");
        $subtable = jqGridUtils::Strip($_REQUEST["subgrid"]);
        $rowid = jqGridUtils::Strip($_REQUEST["rowid"]);
        if(!$subtable && !$rowid) die("Missed parameters");
        $grid = new jqGridRender($conn);
        // Write the SQL Query
        $grid->SelectCommand = 'SELECT SUBSTRING(c.product_name ,1,POSITION("(" IN c.product_name)-1) as pname,b.use_quantity,b.buy_quantity-b.use_quantity as unused FROM '.C('DB_PREFIX').'tenantsproduct AS b LEFT JOIN '.C('DB_PREFIX').'products AS c ON b.product_id = c.product_id WHERE org_id= ?';
        // set the ouput format to json
        $grid->dataType = 'json';
        // Let the grid create the model
        $grid->setColModel(null, array(&$rowid));
        // Set the url from where we obtain the data
        // $grid->setUrl('index.php?m=Member&a=maingrid');
        // Set some grid options
        $grid->setUrl('index.php?m=Member&a=subgrid');
        $grid->setGridOptions(array(
            "autowidth"=>true,
            "postData"=>array("subgrid"=>$subtable,"rowid"=>$rowid)));
        // Change some property of the field(s)
        $grid->setColProperty('pname', array("label"=>"产品名称", "width"=>50,"align"=>"center")); 
        $grid->setColProperty('use_quantity', array("label"=>"使用数量", "width"=>50,"align"=>"center")); 
        $grid->setColProperty('unused', array("label"=>"未使用数量", "width"=>50,"align"=>"center")); 


        $subtable = $subtable."_t";
        $pager = $subtable."_p";
        $grid->renderGrid($subtable,$pager, true, null, array(&$rowid), true,true);
        $conn = null;
    }
0 0
原创粉丝点击