2012-02-04 1 views
1

저는 jquery 및 jqgrid를 처음 사용하지만 자바 스크립트에 익숙합니다. 그러나 나는 노력한 후에 jqgrid를 설치할 수 있었다.셀의 내용 (ID뿐 아니라)에 따라 조건부로 레코드 삭제 버튼을 활성화 또는 비활성화하십시오.

나는 '잠금'열의 값에 따라 탐색 모음에서 삭제 기능을 사용하지 못하게하는 해결책을 찾기 위해 노력해 왔습니다. 다음 링크를 읽었습니다 jqgrid: how to set toolbar options based on column value in row selected

하지만 자바 스크립트의 '잠금'셀의 내용을 가져올 수 없습니다. 또한 효과없이 잠금 문자열을 포맷하려고했습니다.

jqgrid는 PHP를 통해로드됩니다. 이 스크립트는 PHP 스크립트는 여기 http://www.trirand.net/demophp.aspx

입니다 다음

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 스크립트에 포함되어 있습니다. 내가 원하는 것은 "잠금"값을 기준으로 행 삭제 버튼을 활성화 또는 비활성화하는 것입니다. 이것이 너무 기본적이고 우스꽝스럽게 보이는 경우 이해하겠다고 알려주십시오.

답변

0

사용자가 그리드의 셀을 클릭하면 전체 행이 선택되고 콜백 함수 onSelectRow이 호출됩니다. 따라서 첫 번째 매개 변수로 rowid (id<tr> 임)가있는 콜백 함수 onSelectRow을 구현해야합니다. onSelectRow 처리기 내부에서 getCell 메서드를 호출 할 수 있습니다. 필요한 경우 숨길 수있는 '잠금'열의 값에 따라 네비게이터 바의 '수정'및 '삭제'버튼을 사용 중지 할 수 있습니다.

그래서 코드는 다음에 대해 할 수 있습니다 : 당신이있는 jqGrid의 새로운 때문에

$('#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'); 

내가 $.jgrid.jqID() 기능의 사용을 언급합니다. 대부분의 경우 if는 입력 매개 변수의 값을 반환합니다 (예제의 경우 'list'). 그리드의 ID (<table> 요소의 ID)에 meta-characters이 포함 된 경우 더 일반적인 경우에 필요합니다. $.jgrid.jqID() 함수는 임의의 메타 문자 앞에 추가 이스케이프 문자 (두 개의 백 슬래시 : \\)를 포함합니다.

+0

솔루션을 적용했지만 json 데이터를 호출하는 PHP 스크립트를 포함하여 내에이 정보를 추가해야합니까? – Kaippally

+0

@ user1188970 : 죄송하지만, 무슨 뜻인지 이해가 안됩니다. 나는 당신이 올바른 방법으로 jqGrid를 사용하는지 확신하지 못한다. 코드 예제는 문서의 [부분] (http://www.trirand.com/jqgridwiki/doku.php?id=wiki:first_grid#html_file)을보십시오. – Oleg

+0

이것은 jason 데이터를 제공하는 PHP 스크립트의 출력입니다. "" "" "1", "페이지": 1, "합계" add_date_timestamp ":"2012-01-27 10:13:01 ","company ":"Global Auto electricals ","email ":"[email protected] ","phone ":"97335784587 ","mobile " : "+ 9714967451348"} ] } – Kaippally

관련 문제