|
The completely custom oper example.
Select some rows and give it a shot.
Please note the server-side price validation.
Пример создания нестандартной пользовательской операции.
Выберите несколько рядов и задайте им цену.
Обратите внимание на валидацию данных на стороне сервера при помощи исключений.
higrid.net嗨网提供电子表格、在线图形等互联网开发及运营技术,提供相关资料及软件下载,分享奇趣网络时事评论!欢迎访问。
部分内容为俄文,higrid计划翻译一下。敬请期待!
php代码和js代码请点击tab查看。
<?php
class jqOperCustom extends jqGrid
{
protected function init()
{
$this->options = array('multiselect' => true,);
$this->table = 'tbl_books';
#Set columns
$this->cols = array(
'id' => array('label' => 'ID',
'width' => 10,
'align' => 'center',
'formatter' => 'integer',
),
'name' => array('label' => 'Name',
'width' => 40,
),
'price' => array('label' => 'Price',
'width' => 15,
'formatter' => 'integer',
),
);
}
protected function opPrice()
{
$price = intval($this->input('price'));
if($price < 1 or $price > 3000)
{
throw new jqGrid_Exception('Incorrect price!');
}
foreach($this->input['id'] as $id)
{
$this->DB->update($this->table, array('price' => $price), intval($id));
}
}
}
<script>
<?= $rendered_grid ?>
//custom button
$grid.jqGrid("navButtonAdd", pager,
{
caption:"Change price",
title:"Custom oper",
icon:"ui-icon-flag",
onClickButton:function () {
var price = prompt("Enter new price.\Number between 1 and 3000");
if (!price) return;
$(this).jqGrid("extRequest",
{
"oper":"price", //oper name
"price":price //and other values
},
{
'selrow':true //add selected rows to request
});
}
});
</script>
|