1

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

2 回答 2

1

TriRand Inc 的 Tony Tomov 在这里http://www.trirand.net/forum/default.aspx?g=posts&m=3021回答了我的问题。

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

$Model = array(
  array("name"=>"RecipientCellular","sorttype"=>"number",  "editrules"=>  array("custom"=>true,  "custom_func"=>"js:".$checkNumber), "editable"=>true)
);
于 2010-10-28T07:45:41.297 回答
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);
于 2013-12-10T08:09:12.087 回答