1.js设置
//=====================数据加载===================== /** * grid加载数据 * * @returns */ function gridLoad() { $('#t_goods').datagrid({ idField : 'id', // 只要创建数据表格 就必须要加 ifField title : '标的列表', fit : true, url : parent.baseUrl+'goods', // url : '../file/uploadImg', method : 'GET', fitColumns : true, striped : true, // 隔行变色特性 nowrap : false, loadMsg : '数据正在加载,请耐心的等待...', rownumbers : true, sortName : 'crtTime', sortOrder : 'desc', rowStyler : function(index, record) { }, frozenColumns : [ [ // 冻结列特性 ,不要与fitColumns 特性一起使用 { field : 'ck', width : 50, checkbox : true } ] ], columns : [ [ { field : 'goodsNo', title : '内部代码', width : 80, sortable :true, align : 'center' }, { field : 'name', title : '标的名称', width : 80, sortable :true, align : 'center' }, { field : 'plateNum', title : '车牌号', width : 80, sortable :true, align : 'center' },{ field : 'firstTypeName', title : '标的类型', width : 50, sortable :true, align : 'center' }, { field : 'secondTypeName', title : '标的小类', width : 50, sortable :true, align : 'center' },{ field : 'provinceItemName', title : '标的所在省', width : 50, sortable :true, align : 'center' }, { field : 'cityItemName', title : '标的所在市', width : 50, sortable :true, align : 'center' }, { field : 'qtyFact', title : '实收数量', width : 30, align : 'center' }, { field : 'unit', title : '计量单位', width : 25, align : 'center' }, { field : 'storage', title : '库存', width : 50, align : 'center', formatter : storageFtt }, /*{ field : 'announcement', title : '公告', width : 50, align : 'center', formatter : announcementFtt }, */{ field : 'auction', title : '拍卖/变卖日志', width : 50, align : 'center', formatter : auctionFtt }, { field : 'crtTime', title : '创建时间', width : 60, sortable :true, align : 'center' }, { field : 'action', title : '操作', width : 80, align : 'center', formatter : actionFtt } ] ], onLoadSuccess:function(data){ if(top.checkHiddenSet("plateNumFlag")){ $("#t_goods").datagrid("hideColumn", "plateNum"); // 设置隐藏列 } } , pagination : true, pageSize : 10, pageList : [ 5, 10, 15, 20, 50 ], toolbar : toolbarFtt() }); };
2.controller控制器代码
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }) @ResponseBody public ListWithTotalCount<GoodsDTO> auctionGoodsQuery(@ModelAttribute("selectedAgency") SysAgencyDto selectedAgency, String goodsNo, String name, String goodsType, int page, int rows, String order, String sort) { Pageable pageable; String agencyId = selectedAgency.getId().toString(); if (sort != null && !sort.isEmpty()) { pageable = new PageRequest(page - 1, rows, Direction.fromStringOrNull(order), sort); } else { pageable = new PageRequest(page - 1, rows); } if (logger.isDebugEnabled()) { logger.debug("auctionGoodsQuery, goodsNo: {}, name: {}, goodsType: {}", goodsNo, name, goodsType); } Specification<Goods> spec = (root, query, cb) -> { List<Predicate> predicates = new ArrayList<Predicate>(); if (goodsNo != null && !goodsNo.isEmpty()) { Predicate predicate = cb.like(root.get(Goods_.goodsNo), "%" + goodsNo + "%"); predicates.add(predicate); } if (name != null && !name.isEmpty()) { Predicate predicate = cb.like(root.get(Goods_.name), "%" + name + "%"); predicates.add(predicate); } if (agencyId != null && !agencyId.isEmpty() && !"0".equals(agencyId)) { Predicate predicate = cb.equal(root.get(Goods_.agencyId), agencyId); predicates.add(predicate); } if (goodsType != null && !goodsType.isEmpty()) { Predicate predicateAuctionType = cb.like(root.get(Goods_.firstType).get(GoodsType_.name), "%" + goodsType + "%"); Predicate predicateAuctionSmlType = cb.like(root.get(Goods_.secondType).get(GoodsType_.name), "%" + goodsType + "%"); Predicate predicate = cb.or(new Predicate[] { predicateAuctionType, predicateAuctionSmlType }); predicates.add(predicate); } if (!predicates.isEmpty()) { return cb.and(predicates.toArray(new Predicate[0])); } else { return null; } }; Page<Goods> pageresult = goodsRepository.findAll(spec, pageable); List<GoodsDTO> dtoList = (new GoodsDTOAssembler()).toDTOList(pageresult.getContent()); return new ListWithTotalCount<GoodsDTO>(dtoList, (int) pageresult.getTotalElements()); }
3.页面展示效果