[英]Conditionally enable or disable delete record button based on the Content of the cell (not just the the id)
我是jquery和jqgrid的新手,但是我对javascript很满意。 但是,经过一些努力,我设法安装了jqgrid。
我一直在尝试寻找一种解决方案,以基于“锁定”列的值启用或禁用导航栏中的删除功能。 我阅读了以下链接jqgrid:如何根据所选行中的列值设置工具栏选项
但是我无法获取JavaScript的“锁定”单元格的内容。 我也尝试格式化锁定字符串,但没有任何效果。
jqgrid是通过php加载的。 脚本在这里http://www.trirand.net/demophp.aspx
php脚本如下
require_once("JQGrid/jq-config.php");
require_once("JQGrid/php/jqGridASCII.php");
require_once("JQGrid/php/jqGridPdo.php");
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
$grid = new jqGridRender($conn);
$grid->SelectCommand = 'SELECT * FROM `device_assignement` ';
$grid->dataType = 'json';
$grid->setColModel();
$grid->setUrl('Grid_ecu_display.php');
$grid->setColProperty("company",
array("label"=>"Dealer Name",
"width"=>350
),
array( "searchrules"=>
array("searchhidden"=>false, "required"=>false, "search"=>false)));
$grid->setGridOptions(array(
"sortable"=>true,
"rownumbers"=>true,
"rowNum"=>40,
"rowList"=>array(10,50,100),
"sortname"=>"ecu",
"width"=>940,
"height"=>400,
"shrinkToFit"=>true,
"hidden" => true,
"hoverrows"=>true ));
$grid->toolbarfilter = true;
$grid->setFilterOptions(array("stringResult"=>true));
$grid->setColProperty("ecu", array(
"label"=>"ECU Number" ,
"sortable"=>true
));
$grid->setColProperty("lock", array(
"label"=>"<i>Lock</i>" ,
"width"=>60,
"sortable"=>false,
"editable"=>true
));
等等等等
$ecu = jqGridUtils::GetParam('ecu');
// This command is executed immediatley after edit occur.
$grid->setAfterCrudAction('edit', "UPDATE `ecu_master` SET `lock` = '1' WHERE `ecu` =?",array($ecu));
$grid->navigator = true;
$grid->setNavOptions('navigator', array("pdf"=>true, "add"=>false,"edit"=>true,"del"=>false,"view"=>false, "excel"=>true));
$grid->setColProperty('company',array("searchoptions"=>array("sopt"=>array("cn"))));
$oper = jqGridUtils::GetParam("oper");
if($oper == "pdf") {
$grid->setPdfOptions(array(
// set the page orientation to landscape
"page_orientation"=>"L",
// enable header information
"header"=>true,
// set bigger top margin
"margin_top"=>27,
// set logo image
//"header_logo"=>"logo.gif",
// set logo image width
//"header_logo_width"=>30,
//header title
"header_title"=>"Autograde CMS ECU Allocation List",
// and a header string to print
"header_string"=>"$SoftwareVersion"
));
}
// Run the script
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
这包含在另一个php脚本中。 我只想根据“锁定”值启用或禁用“删除行”按钮。如果这看起来太基本和荒谬,请告诉我,我会理解。
如果用户单击网格的某个单元格,则将选择整行,并将调用回调函数onSelectRow 。 因此,您应该实现将以rowid( <tr>
的id
)作为第一个参数的onSelectRow回调函数。 在onSelectRow
处理程序内部,您可以调用getCell方法。 根据“锁定”列的值(必要时可以将其隐藏),可以启用导航栏的“编辑”和“删除”按钮。
因此,代码可以与以下内容有关:
$('#list').jqGrid({
... all other jqGrid options which you need
pager: '#pager',
onSelectRow: function (rowid) {
var gridId = $.jgrid.jqID(this.id);
// test 'lock' column for some value like 'yes'
if ($(this).jqGrid('getCell', rowid, 'lock') === 'yes') {
// disable the "Edit" and "Delete" buttons of the navigator
$("#edit_" + gridId).addClass('ui-state-disabled');
$("#del_" + gridId).addClass('ui-state-disabled');
} else {
// enable the "Edit" and "Delete" buttons of the navigator
$("#edit_" + gridId).removeClass('ui-state-disabled');
$("#del_" + gridId).removeClass('ui-state-disabled');
}
}
}).jqGrid('navGrid', '#pager');
因为您是jqGrid的新手,所以我想评论$.jgrid.jqID()
函数的用法。 在大多数情况下,if返回输入参数的值:在本示例中为'list'。 如果网格的ID( <table>
元素的ID)包含meta-characters,则是更常见的情况。 $.jgrid.jqID()
函数在任何元字符之前包含其他转义符(两个反斜杠: \\\\
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.