<?php
defined
('IN_SHEYI') || define('IN_SHEYI'true); // 常量定义
require(str_replace('\\','/',dirname(__FILE__)).'/config.php');
$connhigrid = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$connhigrid->query("SET NAMES utf8");
// Create the jqGrid instance
$grid = new hgGridRender($connhigrid);//实例化一个对象
$grid->higridSC 'SELECT * FROM cd_chanzhi';
//嗨网higrid:执行SQL查询,可自定义SQL语句
$grid->table 'cd_chanzhi';//本数据库的表名称
$grid->setPrimaryKeyId('period');//自动CRUD操作的key,唯一
//$grid->serialKey = false;//需要用户来完成主键的插入(该表主键CustomerID类型varchar) 
// Set output format to json
$grid->dataType 'json';
// Let the grid create the model
$grid->setColModel(); //default
// initialsearch 
$sarr = <<< FFF
{ "groupOp":"AND",
    "rules":[
      {"field":"period","op":"bw","data":"2014"}
     ]
}
FFF;
//嗨网higrid:隐藏部分列。默认所有列显示
$grid->higridsCP('period'
        array(
"label"=>"月份","width"=>"30",'align'=>'center',"formatter"=>"date",
            
"formatoptions"=>array("srcformat"=>"Y-m-d""newformat"=>"Y-m"),
             
"editoptions"=>array(
            
"defaultValue"=>date("Y-m-d"),
            
"dataInit"=>
                
"js:function(elm){setTimeout(function(){
                    jQuery(elm).datepicker({dateFormat:'yy-mm-dd'});
                    jQuery('.ui-datepicker').css({'font-size':'75%'});
                },200);}"
)
            ));
//设置每个字段名称,宽度,类型,是否必填?默认字符,筛选过滤选项等等
$grid->higridsCP('ycommission', array("width"=>"60",'align'=>'right'"formatter"=>"number",'label'=>'配合调试',));
$grid->higridsCP('ycc2', array("width"=>"80",'align'=>'right'"formatter"=>"currency",'label'=>'主合同',));
$grid->higridsCP('mcommission', array("width"=>"60",'align'=>'right'"formatter"=>"currency",'label'=>'配合调试',));
$grid->higridsCP('mcc2', array("width"=>"60",'align'=>'right'"formatter"=>"currency",'label'=>'主合同',));
//嗨网higrid:post数据处理文件,一般设置本脚本文件路径
$grid->setUrl(GRIDPATH.'cd_chanzhi.php');
// Set some grid options
$grid->higridsGO(array(
    
"rownumbers"=>true,//设置显示行号
   //"rownumWidth"=>35,//设置显示行号的宽度 
    
"caption"=>"项目产值",//标题
    
"hoverrows"=>true,//变色,滑过行高亮显示
    
"altRows"=>true,//多选
    
"rowNum"=>200,//默认行数
    //'width'=>600 //设置Grid宽度(该宽度可以指定为列宽度之和+20px的滚动条宽度) 
    
"height"=>300,
    
"rowList"=>array(20,50,100,200),
    
//"sortname"=>"ProductionMonth",//默认按CustomerID的asc排序
    
"sortable"=>true//设置列与列之间可以拖拽表头排序 
    //"shrinkToFit" => true,
    //"forceFit" => true,
    //'height'=>500, //设置Grid高度,默认为150 
    
"search"=>true
    
// setr criteria
    
"postData"=>array( "filters"=> $sarr ),
    
'sortorder'=>'desc'));//指定排序方式 asc desc
//'height'=>500, //设置Grid高度,默认为150 
    //'viewrecords'=>true //查看总的记录数,默认为true 
    //'loadtext'=>'loading...', //加载文本,默认为loading... 
    //'multiselect'=>true, //是否启用多选功能 
    //"autowidth"=>true, //自适应宽度 
// The primary key should be entered
//$grid->higridsCP('wpid', array("editrules"=>array("required"=>true)));
//$grid->higridsCP("ShipCity",array("editable"=>false));
//$grid->setSelect('CustomerID', "SELECT CustomerID, CompanyName FROM customers");
// Set the custom code for the fields
//设置CustomerID为只读,不可修改(这种情况下该例子的主键将不能被添加,所以不启用)
//$grid->higridsCP('CustomerID', array("editoptions"=>array("readonly"=>true)));
//$grid->higridsCP('Phone',array("formoptions"=>array("rowpos"=>1,"colpos"=>2)));
//colpos - defines the column position of the field edit control 
//rowpos - defines the row position of the field edit control 
//$grid->higridsCP('CompanyName',array(
//    "formoptions"=>array("label"=>"Company", "elmsuffix"=>"(required)"),
//    "editrules"=>array("required"=>true))
//);
//elmpreffix - what to display before the edit control .elmsuffix - what to display after the edit control 
//$grid->higridsCP("date",array("label"=>"Date", "editoptions"=>array("value"=>date("Y-m-d"), "readonly"=>true)));
// The primary key should be entered //定义编辑规则,CustomerID必须填写 //'sortable'=>false可以禁止列的排序功能
//$grid->higridsCP('CustomerID', array("editrules"=>array("required"=>true),'width'=>150, 'align'=>'center', 'label'=>'顾客名称'));
//$grid->higridsCP('Phone', array("width"=>"150",'align'=>'center', 'label'=>'联系电话'));//定义导出ShipName这列的数据
//导航是否显示
$grid->navigator true;
//页面编辑设置true可用;false不显示、不可用
$grid->higridsNO('navigator', array("excel"=>true,"add"=>false,"edit"=>false,"del"=>false,"view"=>true"refresh"=>true,"search"=>true,"pdf"=>true));
// Close the dialog after the record is added //设置添加对话框的信息
$grid->higridsNO('add',array("width"=>500,"height"=>380,"dataheight"=>"auto",
"closeAfterAdd"=>true,"reloadAfterSubmit"=>true));//添加数据完后关闭对话框
// Close the dialog after editing  //设置编辑对话框的信息,//编辑完数据后关闭对话框并修改对话框标题和提交按钮文本
$grid->higridsNO('edit',array("width"=>500,"height"=>380,"dataheight"=>"auto",
"closeAfterEdit"=>true,"reloadAfterSubmit"=>true,"editCaption"=>"编辑数据","bSubmit"=>"更新"));
//$grid->higridsNO('edit',array("closeAfterEdit"=>true,"width"=>470,"height"=>170,"dataheight"=>100)); 
//$grid->higridsNO('edit', array("height"=>110,"dataheight"=>"auto"));
// At end call footerData to put total  label  //添加脚注统计信息
// Enable footerdata an tell the grid to obtain it from the request
//$grid->debug = true;
$oper hgGridcommon::GetParam("oper"); 
// prevent some executions when not excel export 
if($oper == "pdf") { 
    
$grid->setPdfOptions(array( 
        
// set the page orientation to landscape 
        
"page_orientation"=>"R"//L
        // enable header information 
        
"header"=>true
        
// set bigger top margin 
        
"font_name_main"=>"stsongstdlight",
        
"font_monospaced"=>"stsongstdlight",
        
"font_name_data"=>"stsongstdlight",
        
"margin_top"=>27
        
// set logo image 
        
"header_logo"=>"logo.gif"
        
// set logo image width 
        
"header_logo_width"=>30
        
//header title 
        
"header_title"=>"产值情况                             请勿分发 打印时间:".date("Y-m-d H:i:s"), 
        
// and a header string to print 
        
"header_string"=>"商务管理"
        
)); 

$grid->pdffile =date("Ymd_H:i:s").'产值.pdf';
$grid->exportfile =date("Ymd_H:i:s").'产值.xls';
// Set summary field
//$summaryrows=array("Freight"=>array("Freight"=>"SUM"));//SUM MAX MIN AVERAGE COUNT要注意大写
//$grid->higridsGO(array("footerrow"=>true,"userDataOnFooter"=>true));//启用脚注行
//$grid->callGridMethod('#grid', 'footerData', array("set",array('PostalCode'=>'统计:')));
//$grid->higridOP('#grid','#pager',true, null, null, true,true);
// Add a summary property to the Freight Column
//$grid->higridsCP("Freight", array("summaryType"=>"sum", summaryTpl=>"Sum: {0}", "formatter"=>"number"));
$grid->higridsGO(array("footerrow"=>true,"userDataOnFooter"=>true));//启用脚注行
$grid->callGridMethod('#cd_chanzhigrid''footerData', array("set",array('period'=>'小计:')));
// Set grouping header using callGridMethod
$grid->callGridMethod("#cd_chanzhigrid""setGroupHeaders", array(array(
    
"useColSpanStyle"=>true,
    
"groupHeaders"=>array(
        array(
            
"startColumnName"=>'ycommission'
            
"numberOfColumns"=>2
            
"titleText"=>'年初计划'
        
),
        array(
            
"startColumnName"=>'mcommission'
            
"numberOfColumns"=>2
            
"titleText"=>'每月上报'
        
)
    )
)));
$summaryrows = array("ycommission"=>array("ycommission"=>"SUM"),
"ycc2"=>array("ycc2"=>"SUM"),
"mcommission"=>array("mcommission"=>"SUM"),
"mcc2"=>array("mcc2"=>"SUM"),);
//最终表格的table div id,pager div id
//本页的html代码<table id='cd_lettergrid'></table><div id='cd_letterpager'></div>
$grid->higridOP('#cd_chanzhigrid','#cd_chanzhipager',true$summaryrowsnulltrue,true);
$connhigrid null;