easyui-datagrid 매개 변수 조회 실례

<script>
	$(function(){
		$('#dataFileControl').datagrid({
			url: 'audit/sysAuditAction!list.do',
			title: '',
			width: 'auto',
			height: '400',
			//fitColumns: true,
			//showFooter:true,
			nowrap:false,
			autoRowHeight: false,
			striped: true,
			collapsible:true,
			sortName: 'sbtsrc',
			sortOrder: 'desc',
			remoteSort: false,
			idField:'sbtsrc',
			frozenColumns:[[
				{field:'ck',checkbox:true},
				{field:'sbtsrc',title:'Source',width:50,sortable:true},
				{field:'sbtabk',title:'Area Bank',width:70,sortable:true}
			]],
			columns:[[
				
				{field:'sbtstn',title:'Station',width:50,sortable:true},
				{field:'fileName',title:'File Name',width:180,sortable:true},
				{field:'sbtrpd',title:'Reporting Period',width:100,sortable:true},
				{field:'count',title:'Count',width:80,sortable:true,align:'right'},
				{field:'batchNo',title:'Batch No.',width:150,sortable:true},
				{field:'sbtras',title:'Status',width:80,sortable:true},
				{field:'loadID',title:'Load ID',width:80,sortable:true},
				{field:'loadTime',title:'Load Time',width:120,sortable:true},
				{field:'sbtcur',title:'Curr',width:80,sortable:true},
				{field:'sbtsra',title:'Ret',width:80,sortable:true}
				
			]],
			pagination:true,
			rownumbers:true,
			toolbar:[{
				id:'btnSYSAudit',
				text:'SYS Audit',
				handler:function(){
					var batchNos = [];
					var rows = $('#dataFileControl').datagrid('getChecked');
					
					if (rows.length > 0) {
						$.messager.confirm(' ', ' ?', function(r) {
							if (r) {
								for(var i=0;i<rows.length;i++){
									if(rows[i].sbtras=='L'){
										
									}else{
										batchNos.push(rows[i].batchNo);
									}
								}
								//alert(batchNos.join(','));
								$.ajax({
									url : 'test/testtAction!test.do',
									data : {
										batchNos : batchNos.join(',')
									},
									dataType : 'json',
									success : function(response) {
										$.messager.show({
											title : ' ',
											msg : ' !'
										});
									}
								});
							}
						});
					} else {
						$.messager.alert(' ', ' !', 'info');
					}
				}
			},'-',{
					id:'btnSchedule',
					text:'Schedule',
					handler:open1
			}
			]
		});
	});
 $("#search").click(function (){ var param=serializeObject($('#form1')); $("#dataFileControl").datagrid('load',param); }); }); //  serializeObject = function(form) { var o = {}; $.each(form.serializeArray(), function(index) { if (o[this['name']]) { o[this['name']] = o[this['name']] + "," + this['value']; } else { o[this['name']] = this['value']; } }); return o; };
	
	// 
	$(function(){
	 
	$("#panel_reportingPeriod").datebox({
		formatter:formatDate
		});
	})
	// 
	function formatDate(date){
		var y = date.getFullYear();
		var m = date.getMonth()+1;
		var d = date.getDate();
		return y+""+(m<10?"0"+m:m)+""+(d<10?"0"+d:d);// :20121002
		}
	
	function reset(){
		$('#form1').form('clear');
	}
</script>

 
 /**
     *  
     * 
     * @return
     */
    public String list() {

        PageModel<Batch> pm = new PageModel<Batch>(getRequest());
        Map<String, Object> params = pm.getParams();

        String source = getRequest().getParameter("panel_Source");
        String areaBank = getRequest().getParameter("panel_AreaBank");
        String station = getRequest().getParameter("file_station");
        String reportingPeriod = etRequest().getParameter("panel_reportingPeriod");
        String batchNo = getRequest().getParameter("panel_batchNo");
        String status = getRequest().getParameter("panel_Status");

        if (source != null && !"".equals(source)) {
            params.put("sbtsrc", "%" + source + "%");
        }
        if (areaBank != null && !"".equals(areaBank)) {
            params.put("sbtabk", "%" + areaBank + "%");
        }
        if (station != null && !"".equals(station)) {
            params.put("sbtstn", station);
        }
        if (reportingPeriod != null && !"".equals(reportingPeriod)) {
            params.put("sbtrpd", "%" + reportingPeriod + "%");
        }
        if (batchNo != null && !"".equals(batchNo)) {
            params.put("batchNo", batchNo);
        }
        if (status != null && !"".equals(status)) {
            params.put("sbtras", status);
        }
        pm.setParams(params);
        pm = sysAuditService.getByCondition(pm);
        batchMap.put("total", pm.getTotal());
        batchMap.put("rows", pm.getList());
        return "list";
    }

 
    /*
     *  
     * PageModel 
     */
    public PageModel<E> getByCondition(PageModel<E> pageModel) {
        String queryCondition = prepareQueryString(pageModel.getParams());
        return dao.getByCondition(queryCondition, pageModel);
    }

 
    /**
     *  
     * 
     * @param queryString
     *             sql
     * @param params
     *             
     * @return
     */
    @SuppressWarnings("unchecked")
    public PageModel<E> getByCondition(String queryString,PageModel<E> pageModel) {

        Query query = getEntityManager().createQuery(queryString);
        //  
        Query queryAll = getEntityManager().createQuery(queryString);
        //  
        Map<String, Object> params = pageModel.getParams();
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            Object value = entry.getValue();
            String key = entry.getKey();
            if (!key.equals("sort") && !key.equals("order") && value != null
                    && !"".equals(value)) {
                query.setParameter(key, value);
                queryAll.setParameter(key, value);
            }

        }

        //  
        List<E> list = queryAll.getResultList();
        //  
        if (list == null) {
            pageModel.setTotal(0);
        } else {
            pageModel.setTotal(list.size());
        }

        //  
        if (pageModel.getFirstResult() <= 0) {
            query.setFirstResult(0);
        } else {
            int firstresult = pageModel.getTotal() - pageModel.getRows() < 0 ? 0
                    : pageModel.getTotal() - pageModel.getRows();
            query.setFirstResult(pageModel.getFirstResult() >= pageModel
                    .getTotal() ? firstresult : pageModel.getFirstResult());
        }

        query.setMaxResults(pageModel.getRows());
        pageModel.setList(query.getResultList());

        return pageModel;
    }

 
/**
 * 
 *  , 

 * 
 * @version v1.0
 * @author wangxiaopeng
 * @date 2011-11-30  04:12:18
 */
public class PageModel<E> implements Serializable {
	private static final long serialVersionUID = -2778873382939204283L;

	/**
	 *  
	 */
	private int page = 1;

	/**
	 *  
	 */
	private int rows = 15;

	/**
	 *  
	 */
	private int total;

	/**
	 *  
	 */
	private List<E> list = new ArrayList<E>();

	/**
	 *  
	 */
	private Map<String, Object> params = new HashMap<String, Object>();

	public PageModel() {

	}

	public PageModel(HttpServletRequest request) {
		String page = request.getParameter("page");
		String rows = request.getParameter("rows");
		String sort = request.getParameter("sort");
		String order = request.getParameter("order");
		if (page != null && rows != null ) {
			this.page = Integer.valueOf(page);
			this.rows = Integer.valueOf(rows);
		}
		if (sort != null && order != null) {
			params.put("sort", sort);
			params.put("order", order);
		}
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	/**
	 *  

	 * 
	 * @return
	 */
	public int getFirstResult() {
		return rows * (page - 1);
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public List<E> getList() {
		return list;
	}

	public void setList(List<E> list) {
		this.list = list;
	}

	public Map<String, Object> getParams() {
		return params;
	}

	public void setParams(Map<String, Object> params) {
		this.params = params;
	}

}

좋은 웹페이지 즐겨찾기