我也是jqGrid的新手,需要一些帮助。 我需要在我正在编辑的字段上进行自定义验证。
我查看了示例并尝试了下面的代码,但得到错误“自定义检查时应该存在自定义函数!”。请帮助新手!!!“
<?php
$grid->SelectCommand = 'SELECT * FROM sms_recipients';
$grid->table = 'sms_recipients';
$grid->dataType = 'json';
$checkNumber = <<<CHECKER
function checkLength(value, colname) {
if (value < 0 && value >20)
return [false,"Please enter value between 0 and 20"];
else
return [true,""];
}
CHECKER;
$Model = array(
array("name"=>"RecipientCellular", "sorttype"=>"number","editrules"=>array("custom"=>true, "custom_func"=>"$checkNumber"), "editable"=>true)
);
$grid->setColModel($Model);
$grid->setUrl('/src/content/grids/recipients/add_recipients.php');
$grid->setGridOptions(array("rowNum"=>grid_num_rows, "rowList"=>$grid_rows, "hoverrows"=>grid_hover, "width"=>grid_width, "height"=>grid_height, "sortname"=>"RecipientSurname"));
$grid->navigator = true;
$grid->setNavOptions('navigator', array("excel"=>false,"add"=>true,"edit"=>true,"del"=>false,"view"=>false, "search"=>false));
$grid->renderGrid('#jqGrid','#pager',true, null, null, true,true);
$conn = null;
?>
答案 0 :(得分:1)
不使用时自定义javascript代码 添加了某些jqGrid PHP方法 在代码之前使用前缀js:
$Model = array(
array("name"=>"RecipientCellular","sorttype"=>"number", "editrules"=> array("custom"=>true, "custom_func"=>"js:".$checkNumber), "editable"=>true)
);
答案 1 :(得分:0)
你可以参考这个链接 http://www.trirand.net/forum/default.aspx?g=posts&m=3021
$grid->SelectCommand = 'SELECT Serial_Number_Verification_Id,SerialNum,ManufacturingDate FROM serialnumberverification';
// Set the table to where you add the data
$grid->table = 'serialnumberverification';
// Let the grid create the model
$Model = array(
array("name"=>"Serial_Number_Verification_Id", "index"=>'SerialID' ,"width"=>'1'),
array("name"=>"SerialNum", "index"=>'SerialNum' ,"width"=>'1'),
array("name"=>"ManufacturingDate", "index"=>'ManufacturingDate' ,"width"=>'80',"sorttype"=>'date', 'datefmt'=>'Y/m/d', 'align'=>'right')
);
$grid->setColModel($Model);