关闭

easyui级联

138人阅读 评论(0) 收藏 举报
分类:


当‘设备类型选择‘其它’时,‘故障原因分析‘’和’维修方案’的检查项为‘其它’。

1.两个数据源分别是diags3和diags,diags为后台传过来的一串检查项,diags3为‘其它’
var diags3=[{'diag_item_num':'15','diag_item_name':'其他'}];
var totaldiags=diags3;
2.当‘设备类型’选择‘其它’时,清空‘’故障原因分析 ’和维修方案的数据
 
$('#trouble_device_type').combobox({
		valueField:'id',
		textField:'text',
		data : parent.dicData["trouble_device_type"],
		panelHeight : '85',
		onChange:function(value){
		//若选择'其他',清空故障原因分析和维修方案的数据
			if(value=='other'){
				$("#fail_reason").datagrid('loadData',{total:0,rows:[]});
				$("#fix_plan").datagrid('loadData',{total:0,rows:[]});
			}
		}
		
});

3.在datagrid的onBeforeEdit里根据条件判断来重新跟检查项赋值
reasonGrid = $('#fail_reason').edatagrid({
		//height: 200,
		singleSelect: true,
		//fit: true, 
		rownumbers: true,
		selectOnCheck: true,
		multiSort: true,
		idField: 'reason_id',
		url: '',
		pagination: false,
	    columns: [[
	    	{field: 'diag_item_name', title: '检查项', align: 'left', width: 120,
				editor:{
	                type:'combobox',
	                options:{
					    editable: false,
					    valueField:'diag_item_name',
					    textField:'diag_item_name',
					    <span style="color:#ff0000;">data:diags,</span>
					    onSelect: function(record){
	    		 			var index = reasonGrid.datagrid('getRowIndex', reasonGrid.datagrid('getSelected'));
	    		 			var curData = $('#fail_reason').datagrid('getData');
	    					var newdiag_item_name = record.diag_item_name;
                			for(var i=0;i<curData.rows.length;i++){
	                    		if(newdiag_item_name==curData.rows[i].diag_item_name){
	                    			$.messager.alert('警告','已选择当前检查项,不允许重复选择');
	                    			window.setTimeout(function(){
	                    					reasonGrid.datagrid('deleteRow',index+1);
									}, 100);				
									return false;
	                    		}
                			}
                			var row = $('#fail_reason').datagrid('getRows')[curReasonIndex];
	             			row.diag_item_num = record.diag_item_num;
					        //级联刷新
					        var ed = reasonGrid.datagrid('getEditor',{index:curReasonIndex,field:'reason_content'});
					        $(ed.target).combogrid('grid').datagrid('load', {diag_item_num: record.diag_item_num});
					    }
	                }
	            }
	        }, 
	    	{field: 'reason_content', title: '故障原因',align: 'left', width: 350,
				editor:{
	                type:'combogrid',
	                options:{
	                    panelWidth:450,
					    idField:'reason_content',
					    textField:'reason_content',
					    mode: 'remote', 
	                    url:'analysis/queryReasons.do',
	                    pagination : true,//是否分页  
	                    rownumbers:true,//序号  
	                    collapsible:false,//是否可折叠的  
	                    fit: true,//自动大小  
	                    pageSize: 20,//每页显示的记录条数,默认为10  
	                    pageList: [20,40,100],//可以设置每页记录条数的列表  
	                    columns:[[
	                        {field:'reason_content',title:'内容',width:260},
	                        {field:'select_times',title:'次数',width:60}
	                    ]],
						onSelect: function (rowIndex, rowData) {
	             			var row = $('#fail_reason').datagrid('getRows')[curReasonIndex];
	             			row.reason_id = rowData.reason_id;
	             			row.reason_content = rowData.reason_content;
	         			},

						onBeforeLoad:function(param){
							var row = $('#fail_reason').datagrid('getRows')[curReasonIndex];
							param.diag_item_num = row.diag_item_num;
						}
	                }
	            }
            },
			{field: 'is_valid', title: '是否有效', align: 'center', width: 60,
				formatter:function(value,row,index){
					for(var i=0;i<valids.length;i++){
						if(valids[i].id == value){
							return valids[i].text;
						}
					}
					return '';
				},
				editor:{
	                type:'combobox',
	                options:{
					    editable: false,
					    valueField:'id',
					    textField:'text',
					    data:valids
	                }
	            }
			}
	        ]],
		toolbar:[             //工具条  
                {text:"增加",iconCls:"icon-add",handler:function(){//回调函数  
                	//先结束其他行编辑
					var rows = reasonGrid.datagrid('getRows');
                	for(var i=0;i<rows.length;i++){
	                    reasonGrid.edatagrid('endEdit', i);
                	}
                    reasonGrid.datagrid('insertRow',{//如果处于未被点击状态,在第一行开启编辑  
                         index: 0,
                         row: {
                         	source_type:'manual'
                         }
                     });
                    reasonGrid.datagrid('beginEdit',0);//没有这行,即使开启了也不编辑
                    //var ed = reasonGrid.datagrid('getEditor',{index:0,field:'diag_item_name'});
                    //$(ed.target).combobox('loadData', diags);
                }},  
                {text:"删除",iconCls:"icon-remove",handler:function(){
                    var rows = reasonGrid.datagrid('getSelections');
                    var index = reasonGrid.datagrid('getRowIndex', reasonGrid.datagrid('getSelected'));
                    if(rows.length<=0)  
                    {
                        $.messager.alert('警告','您没有选择','error');  
                    }
                    else if(rows.length>1)  
                    {
                        $.messager.alert('警告','不支持批量删除','error');  
                    }
                    else if(rows[0].source_type=='auto')  
                    {
                        $.messager.alert('警告','不允许删除系统自动生成诊断项目','error');  
                    }
                    else
                    {
                        $.messager.confirm('确定','您确定要删除第'+(index+1)+'行吗',function(t){  
                            if(t){
                            	reasonGrid.datagrid('deleteRow',index);
                            } 
                        });
                    }
                }}
        ],
       <span style="color:#ff0000;"> onBeforeEdit</span>:function(index,row){
	        row.editing = true;
	        curReasonIndex = index;
	        $('#fail_reason').datagrid('refreshRow', index);
	        //根据'设备类型'给'检查项'动态赋值
			<span style="color:#ff0000;">var trouble_device_type = $("#trouble_device_type").combobox('getValue');//设备类型
			
			if(trouble_device_type=='other'){
				totaldiags=diags3;
			}else if(trouble_device_type=='video'){
				totaldiags=diags;
			}else{
				totaldiags=diags;
			}
			//获得datagrid'检查项'这一列的对象
			var fieldopts=$('#fail_reason').datagrid('getColumnOption',"diag_item_name");
			//重新定义这一列的editor
			fieldopts.editor={
	                type:'combobox',
	                options:{
					    editable: false,
					    valueField:'diag_item_name',
					    textField:'diag_item_name',
					    data:totaldiags,
					    onSelect: function(record){
	    		 			var index = reasonGrid.datagrid('getRowIndex', reasonGrid.datagrid('getSelected'));
	    		 			var curData = $('#fail_reason').datagrid('getData');
	    					var newdiag_item_name = record.diag_item_name;
                			for(var i=0;i<curData.rows.length;i++){
	                    		if(newdiag_item_name==curData.rows[i].diag_item_name){
	                    			$.messager.alert('警告','已选择当前检查项,不允许重复选择');
	                    			window.setTimeout(function(){
	                    					reasonGrid.datagrid('deleteRow',index+1);
									}, 100);				
									return false;
	                    		}
                			}
                			var row = $('#fail_reason').datagrid('getRows')[curReasonIndex];
	             			row.diag_item_num = record.diag_item_num;
					        //级联刷新
					        var ed = reasonGrid.datagrid('getEditor',{index:curReasonIndex,field:'reason_content'});
					        $(ed.target).combogrid('grid').datagrid('load', {diag_item_num: record.diag_item_num});
					    }
	                }
	            }</span>
	    },
	    onAfterEdit:function(index,row){
	        row.editing = false;
	        $('#fail_reason').datagrid('refreshRow', index);
	    },
	    onCancelEdit:function(index,row){
	        row.editing = false;
	        $('#fail_reason').datagrid('refreshRow', index);
	    },
	    onClick:function(index,row){
	        $('#fail_reason').datagrid('selectRow', index);
	    }
	});






0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:14596次
    • 积分:382
    • 等级:
    • 排名:千里之外
    • 原创:25篇
    • 转载:3篇
    • 译文:0篇
    • 评论:0条