[英]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.