使用Editrules的PHP自定义函数jqGrid

使用Editrules的PHP自定义函数jqGrid,php,jqgrid-php,Php,Jqgrid Php,我也是jqGrid的新手,需要一些帮助。 我需要对正在编辑的字段进行自定义验证 我查看了这些示例,并尝试了下面的代码,但出现了错误“在进行自定义检查时,应该存在自定义函数!”。请帮助一个新手 <?php $grid->SelectCommand = 'SELECT * FROM sms_recipients'; $grid->table = 'sms_recipients'; $grid->dataType = 'json'; $checkNumber = <&l

我也是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;
?>

特里兰公司的托尼·托莫夫在这里回答了我的问题

不使用时的自定义javascript代码 添加了某些jqGrid PHP方法 在代码前面加前缀js:


TriRand公司的Tony Tomov在这里回答了我的问题

不使用时的自定义javascript代码 添加了某些jqGrid PHP方法 在代码前面加前缀js:

你可以参考这个链接

你可以参考这个链接

$Model = array(
  array("name"=>"RecipientCellular","sorttype"=>"number",  "editrules"=>  array("custom"=>true,  "custom_func"=>"js:".$checkNumber), "editable"=>true)
);
$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);