JqGrid使用

列菜单【更多筛选能力,包括显示隐藏列】

$grid->setGridOptions(array(
    "colMenu"=>true
    )
$grid->setColProperty("OrderID", array(
    // colMenu for particular column
    "colmenu"=>true,
    // set which actions to perform
    "coloptions"=> array("sorting"=>true, "columns"=> true, "filtering"=>true, "seraching"=>true, "grouping"=>false, "freeze" => true)
));

日期格式

$grid->setColProperty("OrderDate", array(
    "formatter"=>"date",
    "formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"m/d/Y"),
    "search"=>false
    )

$grid->setColProperty('BirthDate', 
        array("formatter"=>"date",
            "formatoptions"=>array("srcformat"=>"Y-m-d H:i:s", "newformat"=>"m/d/Y h:i A"),
            "editoptions"=>array("dataInit"=>
                "js:function(elm){setTimeout(function(){
                    jQuery(elm).datepicker({dateFormat: 'm/d/yy',timeFormat: 'hh:mm TT',separator: ' ' ,ampm: true});
                    jQuery('.ui-datepicker').css({'font-size':'75%'});
                },200);}")
            ));

列冻结[前提是宽度不能自适应]

 $grid->setColProperty("e_title",array("frozen"=>true));
"autowidth"=>false,

取消排序

$grid->setGridOptions(array(
"cmTemplate"=>array("sortable"=>false)

统计

$grid->setGridOptions(array("footerrow"=>true,"userDataOnFooter"=>true));

$grid->callGridMethod('#grid', 'footerData', array("set",array("ShipCity"=>"Total:")))
$summaryrows=array("Freight"=>array("Freight"=>"SUM")); 
$grid->renderGrid('#grid','#pager',true, $summaryrows, null, true,true);

绑定回车键

$bindkeys =<<<KEYS
$("#grid").jqGrid('bindKeys', {"onEnter":function( rowid ) { alert("You enter a row with id:"+rowid)} } );
KEYS;
$grid->setJSCode($bindkeys);

列合并

$grid->setColProperty('LastName', array(
    "cellattr"=>"js:function( rowId, value, rowObject, colModel, arrData){ return ' colspan=2'}",
    "formatter"=>"js:function(value, options, rData){ return rData['TitleOfCourtesy'] + ' ' + value +', '+ rData['FirstName'];}"
));
$grid->setColProperty('FirstName', array(
    "cellattr"=>"js:function( rowId, value, rowObject, colModel, arrData){ return ' style=\"display:none\"'}"
));

临时存储和恢复操作状态

$.jgrid.saveState("grid");
$.jgrid.loadState("grid");

列格式化及排序类型

$Model = array(
    array("name"=>"Integer","width"=>80,
        "formatter"=>"integer",
        "formatoptions"=>array("thousandsSeparator"=>","), "sorttype"=>"integer"),
    array("name"=>"Number","width"=>80,
        "formatter"=>"number", "formatoptions"=>array("decimalPlaces"=>1), "sorttype"=>"number"),
    array("name"=>"Currency","width"=>80,
        "formatter"=>"currency",
        "formatoptions"=>array("decimalPlaces"=>1,"thousandsSeparator"=>",","prefix"=>"$","suffix"=>" USD"), "sorttype"=>"currency"),
    array("name"=>"Email","width"=>120,"formatter"=>"email"),
    array("name"=>"Link","width"=>120,"formatter"=>"link"),
    array("name"=>"Checkbox","width"=>50,"formatter"=>"checkbox")
);

设列不能调宽度

$grid->setColProperty("OrderDate", array(
    "resizable"=>false,

pdf输出

$buttonoptions = array("#pager",
    array("caption"=>"Pdf", "title"=>"Export to Pdf", "onClickButton"=>"js: function(){
        jQuery('#grid').jqGrid('excelExport',{tag:'pdf', url:'grid.php'});}"
    )
);
$grid->callGridMethod("#grid", "navButtonAdd", $buttonoptions);

增加修改时校验

$grid->serverValidate = true;

// Build server validations array
$validations = array(
    'ShipCity' => array("text"=>true, "required"=>true),
    'Freight'=>array("number"=>true,"minValue"=>10,"maxValue"=>50)
);

//set the rules
$grid->setValidationRules($validations);

sanitize不知什么意思

// Enable server validation
$grid->serverValidate = true;

// Enable server side sanitataion

$grid->serverSanitize = true;

// Build server validations array
// set sanitize option to
$validations = array(
    'ShipCity' => array("text"=>true, "required"=>true, "sanitize"=>true),
    'Freight'=>array("number"=>true,"minValue"=>10,"maxValue"=>50, "sanitize"=>true)
);

//set the rules
$grid->setValidationRules($validations);

自己写检验

$custom_check =<<<CUST
function (value , name)
{
if(!isNaN(value)){
   if(parseFloat(value) < 0 ) {
       return[false,"Currency:Value should be greater then 0"];
   } else {
       return[true, ""];
   }
} else {
   return [false, "Currency: Not a number"];
}
}
CUST;
$Model = array(
    array("name"=>"Currency","editable"=>true, "sorttype"=>"number",
        "editrules"=>array("required"=>true, "custom"=>true, "custom_func"=>"js:".$custom_check)),

联合排序

$grid->setGridOptions(array(
    "multiSort"=>true,

列搜索选项

"searchoptions"=>(array("sopt"=>array(),))
['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']意 思为['equal','not equal', 'less', 'less or equal','greater','greater or equal', 'begins with','does not begin with','is in','is not in','ends with','does not end with','contains','does not contain']

参考https://www.cnblogs.com/chenhuichao/p/8268547.html

标签: 无

发表评论: