jqgrid的的思考
function setJqGridModelToTableForPMM(datas){ var models=[]; var that = this; //关系 field_9_4 var jQ_field_9_4 = loadDataOptionForJqGrid("select option_value,option_label from teflow_base_data_detail where master_id='10117'"); //身份证类型 IDENTTYPE 10348 var jQ_IDENTTYPE = loadDataOptionForJqGrid("select option_value,option_label from teflow_base_data_detail where master_id='10348'"); //性别 field_9_8 114 var jQ_field_9_8 = loadDataOptionForJqGrid("select option_value,option_label from teflow_base_data_detail where master_id='114'"); //国籍 field_9_6 115 var jQ_field_9_6 = loadDataOptionForJqGrid("select option_value,option_label from teflow_base_data_detail where master_id='115'"); //职业等级 field_9_15 10125 var jQ_field_9_15 = loadDataOptionForJqGrid("select option_value,option_label from teflow_base_data_detail where master_id='10125'"); //变更终止新增 field_9_19 fieldname ==New/Upd/Dlt 是否修改 var jQ_field_9_19 = loadDataOptionForJqGrid("select option_value,option_label from teflow_base_data_detail where master_id='10271'"); //产品计划 MemCHGPlan_id var jQ_MemCHGPlan_id = loadDataOptionForJqGrid(""); //保险产品 MemCHGProduct_id var jQ_MemCHGProduct_id = loadDataOptionForJqGrid(""); //是否拥有当地医保 field_9_13 10118 var jQ_field_9_13 = loadDataOptionForJqGrid("select option_value,option_label from teflow_base_data_detail where master_id='10118'"); //核保状态 field_9_25 10342 var jQ_field_9_25 = loadDataOptionForJqGrid("select option_value,option_label from teflow_base_data_detail where master_id='10342'"); //备注 field_9_28 10345 var jQ_field_9_28 = loadDataOptionForJqGrid("select option_value,option_label from teflow_base_data_detail where master_id='10345'"); for(var i=0;i<datas.length;i++){ var dataCols=datas[i].FIELD_ID; var colModel = new Object(); //设置通用设置 名字 colModel.name=datas[i].FIELD_ID; //设置通用设置 id colModel.index=datas[i].FIELD_ID; colModel.key=true; colModel.align="center"; colModel.editable=true; //设置通用设置 编辑与可读 //colModel.editable=datas[i].IS_READONLY==1?false:true; //设置通用设置 宽度 if(datas[i].CONTROLS_WIDTH==0||datas[i].CONTROLS_WIDTH=='0'||datas[i].CONTROLS_WIDTH<40){ datas[i].CONTROLS_WIDTH=50; } //设置通用设置 宽度 // colModel.editoptions={}; // colModel.editrules={}; //colModel.editoptions.readonly=datas[i].IS_READONLY==1?true:false; // colModel.editrules.required=datas[i].IS_REQUIRED==0?true:false; //分支编号 field_9_17 textarea if(datas[i].FIELD_TYPE==1){ colModel.edittype="textarea"; colModel.formatter=function(cellvalue, options, rowObject){ temp = "<textarea name='"+colModel.index+"'>"+cellvalue+"</textarea>" return temp; } } if(datas[i].FIELD_TYPE==3){ colModel.edittype="text"; colModel.formatter=function(cellvalue, options, rowObject){ temp = "<input name='"+colModel.index+"' type='text' value='"+cellvalue+"'/>"; return temp; } } if(datas[i].FIELD_TYPE==5){ colModel.edittype="text"; colModel.formatter=function(cellvalue, options, rowObject){ temp = "<input name='"+colModel.index+"' type='text' value='"+cellvalue+"'/>"; return temp; } } if(datas[i].FIELD_TYPE==4){ console.log(colModel.index); colModel.edittype="select"; colModel.formatter=function(cellvalue, options, rowObject){ temp = "<select name='"+colModel.index+"' value='"+cellvalue+"'><option>"+cellvalue+"</option></select>" return temp; } } if(datas[i].FIELD_TYPE==7){ colModel.edittype="select"; colModel.formatter=function(cellvalue, options, rowObject){ temp = "<select name='"+colModel.index+"' value='"+cellvalue+"'><option>"+cellvalue+"</option></select>" return temp; } } /* //变更终止新增 field_9_19 fieldname ==New/Upd/Dlt if(dataCols=="field_9_19"){ colModel.edittype="select"; colModel.editoptions={value:jQ_operation.value} colModel.formatter=function(cellvalue, options, rowObject){ temp = "<select><option>"+cellvalue+"</option></select>" return temp; } } //field_9_4 关系 if(dataCols=="field_9_4"){ colModel.edittype="select"; colModel.editoptions={value:jQ_relation.value} colModel.editrules={required:true,custom:true}; colModel.formatter=function(cellvalue, options, rowObject){ temp = "<select><option>"+cellvalue+"</option></select>" return temp; } } //field_9_8 性别 if(dataCols=='field_9_8'){ colModel.edittype="select"; colModel.editoptions={value:jQ_fmale.value}; colModel.editrules={required:true,custom:true}; colModel.formatter=function(cellvalue, options, rowObject){ temp = "<select><option>"+cellvalue+"</option></select>" return temp; } } //field_9_13 医保 if(dataCols=='field_9_13'){ colModel.edittype="select"; colModel.editrules={required:true,custom:true}; colModel.editoptions={value:jQ_health.value}; colModel.formatter=function(cellvalue, options, rowObject){ temp = "<select><option>"+cellvalue+"</option></select>" return temp; } } //核保状态 field_9_22 field_9_24 PMMfield_9_24 都是核保状态(在不同的表中) if(dataCols=='field_9_25'){ colModel.edittype="select"; colModel.editrules={required:true,custom:true}; colModel.editoptions={value:jQ_underwriting.value}; colModel.formatter=function(cellvalue, options, rowObject){ temp = "<select><option>"+cellvalue+"</option></select>" return temp; } } //国籍 jQ_nationality if(dataCols=='field_9_6'){ colModel.edittype="select"; colModel.editoptions={value:jQ_nationality.value}; colModel.formatter=function(cellvalue, options, rowObject){ temp = "<select><option>"+cellvalue+"</option></select>" return temp; } } //field_9_9 出身日期 if(dataCols=="field_9_9"){ colModel.formatter='date'; colModel.formatoptions={srcformat: 'm/d/Y', newformat: 'Y/m/d'}; } //field_9_12 劳动合同生效日 if(dataCols=='field_9_12'){ colModel.formatter='date'; colModel.formatoptions={srcformat: 'm/d/Y', newformat: 'Y/m/d'}; } //field_9_24 人员变更生效日 if(dataCols=='field_9_24'){ colModel.formatter='date'; colModel.formatoptions={srcformat: 'm/d/Y', newformat: 'Y/m/d'}; } //INIEFFDT 保障起始日期 if(dataCols=='INIEFFDT'){ colModel.formatter='date'; colModel.formatoptions={srcformat: 'm/d/Y', newformat: 'Y/m/d'}; } //field_9_15 职业等级 10213 职业等级(江苏) 在数据库中暂时没有 jQ_grade if(dataCols=='field_9_15'){ colModel.edittype="select"; colModel.editoptions={value:jQ_grade.value}; colModel.formatter=function(cellvalue, options, rowObject){ temp = "<select><option>"+cellvalue+"</option></select>" return temp; } } //IDENTTYPE证件类型 if(dataCols=='IDENTTYPE'){ colModel.edittype="select"; colModel.editoptions={value:jQ_ID.value}; colModel.formatter=function(cellvalue, options, rowObject){ temp = "<select><option>"+cellvalue+"</option></select>" return temp; } } //jQ_remarks 备注 if(dataCols=='field_9_28'){ colModel.edittype="select"; colModel.editoptions={value:jQ_remarks.value}; colModel.formatter=function(cellvalue, options, rowObject){ temp = "<select><option>"+cellvalue+"</option></select>" return temp; } }*/ /*//MemPlan_id 产品计划 注意不同表的关联的formTable4的name 为不同值 包括医保 和 职业等级 if(dataCols=="MemCHGPlan_id"){ colModel.edittype="select"; } if(dataCols=="MemCHGProduct_id"){ colModel.edittype="select"; }*/ models.push(colModel); } return models; } function initJqGridForPMM(section){ jQuery("#formTable9").after("<div id='pager9'></div>"); var lastsel; var sql1 ="SELECT IS_REQUIRED,FIELD_TYPE,IS_READONLY,FIELD_ID ,FIELD_LABEL,CONTROLS_WIDTH FROM TEFLOW_FORM_SECTION_FIELD WHERE FORM_SYSTEM_ID='"+formSystemId+"' AND SECTION_ID='9' ORDER BY ORDER_ID"; var datas =selectFromSQLJson('',sql1); var colNames=[]; //添加(*)字符 for(var i=0;i<datas.length;i++){ if(datas[i].IS_REQUIRED==0) colNames.push(datas[i].FIELD_LABEL+'(*)'); else colNames.push(datas[i].FIELD_LABEL); } var ids = ""; var requestNo = jQuery('input[name="request_no"]').val(); for(var i=0;i<datas.length;i++){ if(i+1==datas.length){ ids+=datas[i].FIELD_ID; }else{ ids+=datas[i].FIELD_ID+',' } } var sql2="SELECT "+ids+" from TEFLOW_"+formSystemId+"_9 WHERE REQUEST_NO='"+requestNo+"'"; var jQgridDatas =getJqGridJSONListBySQL('',sql2); /*var blackList = blackListCheckingForJqgrid(); var productData = getProductDataForJqgrid(); */ var defaults ={ datatype: "local", colNames:colNames, colModel:setJqGridModelToTableForPMM(datas), cellEdit:true, multiselect:true, rowNum:10000, cellsubmit: "clientArray", rowList:[10000,20000,30000], pager:"#pager9", width:jQuery(document).width()*2, viewrecords: true, sortorder: "desc", editurl: 'index.jsp', jsonReader: { repeatitems: false }, afterInsertRow: function(rowid, aData){} } jQuery('#formTable9').jqGrid(defaults); //调用方法 jQuery('#formTable9').jqGrid('bindKeys', {"onEnter":function( rowid ) { alert("You enter a row with id:"+rowid)} } ); jQuery('#formTable9').jqGrid('filterToolbar',{searchOperators : true}); jQuery('#formTable9').jqGrid('navGrid','#pager9',{}); var parameters = { edit: true, editicon: "ui-icon-pencil", add: true, addicon:"ui-icon-plus", save: true, saveicon:"ui-icon-disk", cancel: true, cancelicon:"ui-icon-cancel", addParams : {useDefValues : true}, editParams : {} } jQuery('#formTable9').jqGrid('inlineNav',"#pager9",parameters); for(var i=0;i<=jQgridDatas.jsonArray.length;i++){ jQuery('#formTable9').jqGrid('addRowData',i+1,jQgridDatas.jsonArray[i]); } } function loadDataOptionForJqGrid(sql){ var data_options = getJqGridJSONListBySQL('',sql); var result = {}; var jsonObj={}; var data_val,value_sel,text_sel; for(var i=0;i<data_options.length;i++){ value_sel=data_options[i][0]; text_sel = data_options[i][1]; jsonObj[value_sel]=text_sel; if(i+1==data_options.length){ data_val=value_sel+":"+text_sel; }else{ data_val=value_sel+":"+text_sel+";"; } result.value=data_val; result.arr=jsonObj; } return result; } function getJqGridJSONListBySQL(connectName, sql){ var url = "/formSectionAction.it?method=getJqGridJSONListBySQL"; if(document.all['requestUrl']) url = document.all['requestUrl'].value + url; else if(parent.document.all['requestUrl'].value) url = parent.document.all['requestUrl'].value + url; var param; param = 'dataSQL='+encodeURI(encodeURI(sql)) + '&dataConnectName=' + encodeURI(encodeURI(connectName)); var result; jQuery.ajax({ type: "GET", url: url, dataType: "json", contentType: "application/json", data: param, async: false, success: function (data) { if(data&&data!=null) result = data; }, error: function (XMLHttpRequest, textStatus, errorThrown) { result = ""; } }); return result; }