jquery之mmgrid外掛的使用教程
阿新 • • 發佈:2018-11-03
一、前言
mmgrid官方文件地址為:http://www.jq22.com/demo/mmGrid-master20150916/examples/index.html;雖然有官方文件,但文件中明顯缺少了實際應用的demo,導致很多朋友在看了文件後依然一頭霧水,不知道該如何下手。鑑於這一點,本人基於長期使用mmgrid的經驗,特寫一篇關於mmgrid的使用教程。以便幫助各位同道朋友快速對它上下其手,運用自如。本教程所使用的mmgrid基於原作者做了一定的改動優化,若需使用本人改動後的版本,可留言聯絡。
二、使用
1,jsp html 內容
[plain]2,mmgrid的核心程式碼
[javascript] view plain copy- //初始化表格
- var grid,searchParams;
- function initGrid(){
- //資料列
- var cols =[
- {title: '批次名稱', name:'batchName', width:150, align:'left',hidden:false,limit:150,sortable:true},
- {title: '倉庫編號'
- {title: '倉庫名稱', name:'warehouseName', width:150, align:'left',sortable:true,limit:150}
- ];
- //獲取預設引數
- var gridOpts = getGridDefaultOptions();
- //個性化引數配置
- pgBar = $('.pagenav').mmPaginator({limit: 20});//分頁外掛
- var gridOpts = getGridDefaultOptions();
- gridOpts.height = height;
- gridOpts.plugins = [pgBar];
- gridOpts.fullWidthRows = true;
- gridOpts.sortName = "END_DATE";
- gridOpts.sortStatus = "desc";
- gridOpts.global = false;
- gridOpts.cols = gridDefaultCols;
- gridOpts.url = window.ctx + '/logisticsEval/findLogiEvalRecord.sc?PAGE=LogisticsEvalPO';//資料請求地址
- //遠端資料返回後、載入前的額外處理方法(個人新增)
- gridOpts.gridDataFn = function(data){
- var items = data.items;
- for(var i=0;i 0){
- var scoreObj = {};
- for(var j=0;j
3,mmgrid的請求後,對應的java程式碼處理片段為(使用了springMVC) [java] view plain copy
- /**
- * @author zt
- * @describe 查詢倉庫資訊
- * @time 2017-8-7 下午2:32:21
- * 注意下方key值不可改變
- * respMap.put("items", logiList);//資料
- * respMap.put("totalCount", result.size());//資料總條數
- * MmgridPageBean 物件包含了分頁處理資訊
- */
- @RequestMapping("/findWarehourse")
- @ResponseBody
- public Map findWarehourse(HttpServletRequest request,HttpServletResponse response,MmgridPageBean pageBean,String warehourseName){
- try {
- WarehouseListPopupPage warehouseListPopupPage = new WarehouseListPopupPage();
- String isAll = request.getParameter("isAll");
- Map respMap = new HashMap();
- IUser user = ctx.getUserInfo();
- int[] seIndex = pageBean.getSeIndex();
- if(StringUtils.isBlank(isAll)){
- List logiList = new ArrayList();
- WarehouseInfo whouse = WarehouseInfo.lookWarehouseByUserName(user.getLoginName(),user.getCompanyID());
- List details = LogisticsEvaluationDO.getBatchLogisticsEvaluation(user.getCompanyID(),whouse.getWarehouseId(),warehourseName);
- int endIndex = seIndex[1]>details.size()?details.size():seIndex[1];
- List subDetails = details.subList(seIndex[0],endIndex);
- if(details != null && details.size() >0){
- for(LogisticsEvaluationDO eo:subDetails){
- LogisticsEvalBean bean = new LogisticsEvalBean();
- BeanUtils.copyProperties(bean, eo);
- logiList.add(bean);
- }
- }
- respMap.put("items", logiList);
- respMap.put("totalCount", details.size());
- }else{
- List logiList = new ArrayList();
- Vector result = warehouseListPopupPage.qryWarehouseAll(ctx,warehourseName);
- int endIndex = seIndex[1]>result.size()?result.size():seIndex[1];
- List subResult = result.subList(seIndex[0], endIndex);
- for(int i=0;i
總結:文件中已有的api此處不做說明,很多朋友關心的分頁問題,使用分頁外掛既會自動往後臺傳分頁引數。返回資料時,必須注意key與前臺解析的key的值一致。