开发者

jqGrid for PHP Custom function using Editrules

I am also quite a newby to jqGrid and need some help please. I need custom validation on a field I am editing.

I looked at the examples and tried the following code below but get the error "Custom function should be present in case of custom checking!". Please help a newbie out!!!

<?php
$grid->SelectCommand = 'SELECT * FROM sms_recipients';
$grid->table = 'sms_recipients';
$grid->dataType = 'json';

$checkNumber = <<<CHECKER
    function checkLength(value, colname) {
       开发者_JAVA百科 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;
?>


Tony Tomov from TriRand Inc answered my question here http://www.trirand.net/forum/default.aspx?g=posts&m=3021.

Custom javascript code when not using certain jqGrid PHP methods is added with prefix js: before the code.

$Model = array(
  array("name"=>"RecipientCellular","sorttype"=>"number",  "editrules"=>  array("custom"=>true,  "custom_func"=>"js:".$checkNumber), "editable"=>true)
);


you can refer this link 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜