複製程式碼 程式碼如下: <p>$(document).ready(function()<br>{<br> initPlsfList();<br>});<br>//初始化grid列表<br>function initPlsfList(){<br> //缓存表列数组,key 为页面元素的name ,value 对应数据库中的字段<br> var cellArray = new Array();<br> cellArray["zoneID"] ="ZONE_ID"; <br> cellArray["factorPG"] ="FACTOR_PG"; <br> cellArray["factorQG"] ="FACTOR_QG";<br> cellArray["factorPL"] ="FACTOR_PL";<br> cellArray["factorQL"] ="FACTOR_QL";<br> cellArray["valid"] ="VALID";<br> </p> <p> var caseID = '${caseID}';<br> $("#plsfList").jqGrid({<br> url:"<url value='/lfc/lsfactorctor/IDc/lsfactor/IDqueox caseID "'></url>",<br> 資料類型: "json",<br> mtype:"POST",<br> <br> colNames: [ <br> 'id',<br> "<message key="zone"></message>", <br> message key='pasf'/>", <br> "<message key="pisf lasf"></message>",<br> "<fmt :message key="lisf"></fmt>",<br> 'modeID'<br> : [<br> {name:'id',index:'id', width :100,隱藏: true},<br> {name:'valid',index:'valid', width:100,editable: 🎜> editable:true,edittype:'checkbox',<br> editoptions:{value:'1:0',defaultValue:'1'}<br> }, {name:'factorPG',index:'factorPG', width:100,editable:true},<br> {name:'factorQG',index: {name:'factorQG',index: {name:'factorQG',index:"factor10, widtable> {name:'factorPL',index:'factorPL', width:100,editable:true},<br> {name:'factorQL',index: {name:'factorQL',index: ¢ > {名稱:'caseID',指標:'caseID',寬度:100,:true},<br> um:10,<br> rowList:[10,20,30],<br>尋呼機: '',<br> cellEdit:true,<br> viewrecords: true,<br> ); false,'水平ntal ' ,false],<br>可排序:false,<br> 排序順序:“ asc”,<br> 排序名稱:“ id”,<br> multiSelect:true,<br> cellurl :"<url value=" /lfc/powerlsfactor/save"></url>",<br> cellsubmit: '遠端',<br> gridComplete: function() {<br> gridComplete: var cb_title = “<fmt key="select.all" bundle="${commonResources}"> if($selecAll){<br> $selecAll.attr("title",cb_title);<br> }<br> //设置全选checkbox title<br> var rowIds = jQuery("#plsfList").jqGrid('getDataIDs');<br> for(var k=0; k<rowIds.length; k++) {<BR> var curRowData = jQuery("#plsfList").jqGrid('getRowData', rowIds[k]);<BR> var curChk = $("#"+rowIds[k]+"").find(":checkbox");<BR> //curChk.attr('title', curRowData.modeName); //给checkbox赋予额外的属性值<BR> }<br><br> },<BR> onSortCol:function(index,iCol,sortorder){<BR> return false ;<BR> },<BR> ondblClickRow: function (rowid,iRow,iCol,e) {<BR> /*var $plsfList = $("#plsfList");<BR> if (isRowNeedSave($plsfList)){<BR> showMessage("请先保存");<BR> }else{<BR> $("#operate").val("update");<BR> newrowid = rowid ;<BR> $plsfList.setGridParam({cellEdit:false});<BR> $plsfList.jqGrid('editRow', rowid, true);<BR> //确定按钮可用<BR> $("#confirm_btn").attr("disabled",false);<br><br> }*/<BR> },<BR> beforeSubmitCell:function(rowid, cellname, value, iRow, iCol){<BR> //列提交前的拦截方法<BR> var $plsfList = $("#plsfList") ;<BR> var $editUrl = '<c:url value='/lfc/powerlsfactor/save'/>' ;<br> //设置列提交的url。updateCellName:要编辑的列名 ;updateCellValue :是编辑的值<br> $editUrl = addParamToUrl($editUrl,'updateCellName',iCol == 3 ? cellArray['zoneID'] :cellArray[cellname]);<br> $editUrl = addParamToUrl($editUrl,'updateCellValue',iCol == 3 ? $("#zone_id").val():value);<br> //给jqgrid 从新设置cellurl 值<br> $plsfList.setGridParam({cellurl:$editUrl});<br> return false ;<br> },<br> afterEditCell:function(rowid, cellname, value, iRow, iCol){<br> //动态修改lie时,当列 变为可修改状态时,给列add一个button,且列中元素不可编辑,点击button 弹出一个模态窗口,可以选择元素 ,赋值给grid当前编辑列中单行表单域中.<br> $("#"+rowid+" input[type='checkbox']").attr("checked",value == "<fmt:message key='case.valid'/>" ? true:false);<br> if(iCol==3){<br> $("#irowNum").val(rowid);<br> var $data = $("#"+rowid +">td"); //获取这个行里所有的td元素,即:获取所有子元素<br> $zoneInput = $data.find("input").eq("1") ;<br> $zoneInput.css("width","100px");<br> $zoneInput.attr("disabled",true);<br> $zoneInput.after("<input type='button' value='选择' onclick='fnCallDialogForEidt()' />");<br> }<br> }</fmt></p> <p> });</p> <p><br>//grid新增新的一行<br>var newrowid ;<br>function addRow()<br>{<br> $("#operate").val("");<br> var selectedId = $("#plsfList").jqGrid("getGridParam", "selrow"); <br> var ids = jQuery("#plsfList").jqGrid('getDataIDs');<br> //取得目前最大行號(資料編號)<br> var rowid = Math.max.apply(Math,ids);<br> //取得新新增行的行號(資料編號)<br> newrowid = rowid 1;<br> var dataRow = { <br> id: "",<br> valid:"",<br> 🎜> factorPL: '',<br> factorQL:'',<br> caseID:''<br> }; <br>@ }; <br> ).jqGrid("addRowData", newrowid, dataRow, "first");<br> //設定grid單元格無法編輯<br> $("#plsfList").setGridParam({cellEdit:false}; //設定grid單元格可編輯<br> $('#plsfList').jqGrid('editRow', newrowid, false);<br> //確定按鈕可用<br> attr("disabled",false);<br> //給新增的欄位加選擇按鈕<br> var $zoneInput = $("#" newrowid "_zoneName"); ,true).css("width",100);<br> $zoneInput.after("<input type="button" value="選擇" onclick="fnCallDialogForEidt()">");<br><br>}<br> <br><br>function insertPlsf(){<br> var $plsfList = $("#plsfList") ;<br> var $operate = $("#operate").val();<br> var $operate = $("#operate").val();</p> ///設定grid儲存格可編輯<p> $plsfList.setGridParam({cellEdit:true});<br> //設定grid行不可編輯<br> //$plsfList.jqGrid('editRow', newrowid, false); <br> //拼接請求的url<br> var url = '' "/lfc/powerlsfactor/save" ;<br> var $params = $plsfList.find("input[id^= " newrowid "]");<br> var $check_val = $params.eq(0).is(':checked') ? 1:0;<br> url = addParamToUrl(url,'valid',$check_val) ;<br> url = addParamToUrl(url,'zoneID',$("#zone_id").val());<br> url = addParamToUrl(url,'factorPG',$params.eq(2).val( ));<br> url = addParamToUrl(url,'factorQG',$params.eq(3).val());<br> url = addParamToUrl(url,'factorPL',$params.eq(4). val());<br> url = addParamToUrl(url,'factorQL',$params.eq(5).val());<br><br> var $caseID = $("#caseID").val ();<br> url = addParamToUrl(url,'caseID',$caseID);<br> <br> $.ajax({url:url,type:"post",timeout:5000, <br> success:function(data){<br> 🎜> }<br> });</p> //將新加行號初始為空<p> newrowid = '' ;<br> //確定按鈕不可用<br> $("#confirm_btn").不可用<br> $("#confirm_btn"). "disabled",true);<br>}<br> <br><br>//格式zone欄位輸出內容<br>function formatZone(cellvalue, options, rowObject){<br> if(cellvalue == 0){<br> return 0 if(cellvalue == 0){</p> return 0 if(cellvalue == 0){<p> return 0 if🎜} cellvalue == 1){<br> return 1;<br> }else if(cellvalue == 2){<br> return 2;<br> }else{<br> return 2;<br> }else{<br> return 2;<br> }else{<br> }<br> <br><br>function isRowNeedSave($jqgrid){</p> var $editTr = $jqgrid.find("tr[editable=1]") ;<p> var flag = false ;<br>5 0){<br> flag = true ;<br> }<br> return flag ;<br>}<br> <br><br>function cancel(){</p> reloadGrid();<p> //確定按鈕不可用<br> $("#confirm_btn").attr("disabled",truetrue);<br> //設定grid儲存格可編輯<br> $("#plsfList").setGridParam({cellEdit:true});<br> //設定grid儲存格可編輯<br> $('#plsfList //設定grid儲存格可編輯<br> jqGrid('editRow', newrowid, true);<br>}<br> <br> </p> <p>function fnCallDialogForEidt(){</p> //取得目前行號(資料編號)<p> var returnValue = "";<br> returnValue = window.showModalDialog("<url value='/elelf> zone/query?caseID=" $("#caseID").val() "'></url>",window,"");<br> if(returnValue==""||returnValue==null)<br> return;<br> var $plsfList = $("#plsfList");<br> var $params = $plsfList.find("input[id$='zoneName']");<br> var names = returnValue. split(",");<br> $params.eq(0).val(names[1]);<br> $("#zone_id").val(names[0]);<br>}<br><br><br></p> </div> <img alt="" src="http://files.jb51.net/file_images/article/201311/20131108100036.png">