清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | //服务 class JqGridService { /** * @params params 相关参数(jqGrid向服务器端发的参数) * @param queryBlock 取数据的闭包逻辑 * @param dataFormat 取出数据后具体需要组装成json的数据 */ def createForJson = { params,queryBlock,dataFormat -> def sortIndex = params.sidx ?: 'id' def sortOrder = params.sord ?: 'desc' def maxRows = Integer.valueOf(params.rows ?: 10 ) def currentPage = Integer.valueOf(params.page ?: 1 ) ?: 1 def rowOffset = currentPage == 1 ? 0 : (currentPage - 1 ) * maxRows params. max = maxRows params.offset = rowOffset def dataRows = queryBlock.call(params) def totalRows = dataRows.totalCount def numberOfPages = Math.ceil(totalRows / maxRows) def results = dataRows?. collect { dataFormat(it) } [rows: results, currpage: currentPage, totalrecords: totalRows, totalpages: numberOfPages] } } //控制器调用示例 class MyController{ def jqGridService def listJSON = { //取数据的闭包逻辑 def block = { params -> Article.createCriteria().list( max : params. max , offset: params.offset) { order(params.sidx, params.sord).ignoreCase() } } //取出数据后具体需要组装成json的数据 def format = { row -> [ 'id' :row.id, 'nickname' :row.nickname, 'realname' :row.realname, 'username' :row.username, 'type' :row.type?.name, 'online' :row.online ? '是' : '否' , 'dateCreated' :row.dateCreated?.format( 'yyyy-MM-dd HH:mm:ss' ), 'loginTime' :row.loginTime?.format( 'yyyy-MM-dd HH:mm:ss' ) ] } render jqGridService.createForJson(params,block,format) as JSON } } //页面调用 <script type= "text/javascript" > $(document).ready(function(){ $( '#list' ).jqGrid( { jsonReader : { root: "rows" , page: "currpage" , total: "totalpages" , records: "totalrecords" , repeatitems: false, id: "0" }, url: '${resource()}/admin/user/listJSON' , colNames: [ 'ID' , '登录名' , '昵称' , '真实姓名' , '用户类型' , '注册时间' , '登录时间' , '是否在线' ], colModel: [ {name: 'id' , editable: false}, {name: 'username' , editable: true}, {name: 'nickname' , editable: true}, {name: 'realname' , editable: true}, {name: 'type' , editable: true}, {name: 'dateCreated' , editable: true}, {name: 'loginTime' , editable: true}, {name: 'online' , editable: true} ], sortname: 'id' , caption: '用户列表' , height: 300 , rowNum: 10 , autowidth: true, scrollOffset: 0 , viewrecords: true, pager: '#pager' , datatype: 'json' } ); |