`
longflang
  • 浏览: 64129 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

jquery filexgrid动态列

 
阅读更多

思路:根据相关参数,动态的成对应该的参数列。设置到Flexgrid参数中。

js对应该的方法:

function roleselect(){
    $.ajax({ 
    	url:'workform-main!getColumBySpcode.action?opttype=' +$('#opttype').val(),//请求列信息的地址 
    	dataType:'json', 
    	success:function(data){ 
	    	var json = eval(data);
	    	// op为包含列信息的数组
	    	var op=new Array(); 
	    	// 迭代返回数据 读出读出每个列信息拼装成对象填入数组
	    	$.each(json, function(i,item){
	    		if(i==0){
	    			op.push({display: item.display, name : item.name, width : 50, sortable : true, align: 'center',hide: true,toggle : false});
	    		}else if(i==1){
	    			op.push({display: item.display, name : item.name, width : 80, sortable : true, align: 'center',process:clickrow}); 
	    		}else{
	    			op.push({display: item.display, name : item.name, width : 120, sortable : true, align: 'left'});
	    		} 
	    	}); 
	    	// 重画grid
	    	var w = $("#ptable").width() - 3;
			grid=$("#flexTable").flexigrid({
				width: w ,
				height: 250,
				url: 'workform-main!getData.action?type=' + $('#type').val() ,
				dataType: 'json',
				colModel : op,
				searchitems : [
					{display: '客户编码', name : 'customerid', isdefault: true},
					{display: '客户名称', name : 'customername',operater: "Like"},
					{display: '工单类型', name : 'wftype',operater: "Like"},
					{display: '工单状态', name : 'wfstate',operater: "Like"}
					],
				errormsg: '发生异常',
				sortname: "id",
				sortorder: "desc",
				//qop: "Eq",//搜索的操作符
				usepager: true,
				//title: '详细信息列表',
				//pagestat: '显示记录从{from}到{to},总数 {total} 条',
				useRp: false,
				rp: 10000,
				//rpOptions: [10, 15, 20, 30, 40, 100], //可选择设定的每页结果数
				nomsg: '没有符合条件的记录存在',
				minColToggle: 1, //允许显示的最小列数
				showTableToggleBtn: true,
				autoload: true, //自动加载,即第一次发起ajax请求
				resizable: true, //table是否可伸缩
				procmsg: '加载中, 请稍等 ...',
				hideOnSubmit: true, //是否在回调时显示遮盖
				showcheckbox: true,//是否显示第一列的checkbox(用于全选)
				gridClass: "bbit-grid",//样式
			    rowhandler: contextmenu,//是否启用行的扩展事情功能,在生成行时绑定事件,如双击,右键菜单等
				rowbinddata: true,//配合上一个操作,如在双击事件中获取该行的数据
				onrowchecked: callme,//在每一行的的checkbox选中状态发生变化时触发某个事件
				//onrowchecked: false//在每一行的的checkbox选中状态发生变化时触发某个事件
				
				striped:false,
				blockOpacity: 0.5//透明度设置
			});
    	}	
    });
}

 

java Action 代码:

public String getColumBySpcode() {
		setActionInfo();
		String opttype = this.getRequest().getParameter("opttype");
		JSONArray array = new JSONArray();
		if ("runtype".equals(opttype)) {
			array.put(new JSONObject(new FlexGridColumnVo("编号","id")));
			array.put(new JSONObject(new FlexGridColumnVo("客户编码","customerid")));
			array.put(new JSONObject(new FlexGridColumnVo("电话号码","photono")));
			array.put(new JSONObject(new FlexGridColumnVo("客户名称","customername")));
					}else{
			array.put(new JSONObject(new FlexGridColumnVo("编号","id")));
			array.put(new JSONObject(new FlexGridColumnVo("客户编码","customerid")));
			array.put(new JSONObject(new FlexGridColumnVo("电话号码","photono")));
			array.put(new JSONObject(new FlexGridColumnVo("客户名称","customername")));
						array.put(new JSONObject(new FlexGridColumnVo("客户级别","lever")));
			array.put(new JSONObject(new FlexGridColumnVo("基本商品","basepro")));
			array.put(new JSONObject(new FlexGridColumnVo("CMIP","cmip")));
			array.put(new JSONObject(new FlexGridColumnVo("是否已回填","fullback")));
		}
	
		JSON_OBJECT = array.toString();
		return setJsonObject();
	}

 

	private void setActionInfo() {
		this.getResponse().setContentType("text/html");
		this.getResponse().setCharacterEncoding("utf-8");
		this.getResponse().setHeader("Pragma", "no-cache");
		this.getResponse().setHeader("Cache-Control", "no-cache, must-revalidate");
		this.getResponse().setHeader("Pragma", "no-cache");
	}

 

	private String setJsonObject() {
		try {
			HttpServletRequest request = this.getRequest();
			System.out.println(request.getParameter("username"));
			this.getResponse().getWriter().write(JSON_OBJECT);
			this.getResponse().getWriter().flush();
			this.getResponse().getWriter().close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics