成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? EasyUI學習之DataGird分頁顯示數(shù)據(jù)
全站頭部文字 我要出現(xiàn)在這里
EasyUI學習之DataGird分頁顯示數(shù)據(jù) 844 2024-02-07   

本文實例為大家分享了EasyUI DataGird的使用方法,供大家參考,具體內(nèi)容如下

1. html代碼

<table 
  id="grid" 
  style="width: 940px" 
  title="用戶操作" 
  data-options="iconCls:'icon-view'">
</table>

2.顯示

查看圖片

3.js代碼

// 頁面加載后顯示表數(shù)據(jù)
$(function() {
  var queryData = {};// 可添加一些預設條件
  InitGrid(queryData);// 初始化Datagrid表格數(shù)據(jù)
});

// 實現(xiàn)對DataGird控件的綁定操作
function InitGrid(queryData) {
  $('#grid').datagrid({ // 定位到Table標簽,Table標簽的ID是grid
    url : 'getNoticesByUserId',// 指向后臺的Action來獲取當前用戶的信息的Json格式的數(shù)據(jù)
    title : '公告管理',
    iconCls : 'icon-view',
    height : 650,
    width : function() {
      return document.body.clientWidth
    },// 自動寬度
    pagination : true,
    rownumbers : true,
    sortName : 'title', // 根據(jù)某個字段給easyUI排序
    pageSize : 20,
    sortOrder : 'asc',
    remoteSort : false,
    idField : 'id',
    queryParams : queryData, // 異步查詢的參數(shù)
    columns : [ [ {
      field : 'ck',
      width : '1%',
      checkbox : true
    }, {
      title : '標題',
      field : 'title',
      width : '9%',
      sortable : true,
      halign : 'center'
    }, {
      title : '發(fā)布人',
      field : 'userName',
      width : '10%',
      sortable : true,
      halign : 'center'
    }, {
      title : '內(nèi)容',
      field : 'content',
      width : '50%',
      sortable : true,
      halign : 'center',
      sortable : false
    }, {
      title : '創(chuàng)建日期',
      field : 'createDate',
      width : '20%',
      sortable : true,
      halign : 'center',
      align : 'center',
      sortable : false
    } ] ],
    toolbar : [ {
      id : 'btnAdd',
      text : '添加',
      iconCls : 'icon-add',
      handler : function() {
        ShowAddDialog();// 實現(xiàn)添加記錄的頁面
      }
    }, '-', {
      id : 'btnEdit',
      text : '修改',
      iconCls : 'icon-edit',
      handler : function() {
        ShowEditDialog();// 實現(xiàn)修改記錄的方法
      }
    }, '-', {
      id : 'btnDelete',
      text : '刪除',
      iconCls : 'icon-remove',
      handler : function() {
        Delete();// 實現(xiàn)直接刪除數(shù)據(jù)的方法
      }
    } ]
  });

};

4.Json數(shù)據(jù)

{
  "total": 2,
  "rows":[{
      "content": "11",
      "createDate": "2016-12-15 23:03:50",
      "id": 1,
      "title": "11",
      "userName": "789"

    }, {
      "content": "我是",
      "createDate": "2016-12-16 20:10:03",
      "id": 4,
      "title": "為",
      "userName": "789"
    }
  ]
}

5.Java后臺封裝

/********************1.action代碼*******************/
private NoticeManager noticeManager;
private int page;
private int rows;
Map<String, Object> map = new HashMap<String, Object>();

public NoticeManager getNoticeManager() {
  return noticeManager;
}
public void setNoticeManager(NoticeManager noticeManager) {
  this.noticeManager = noticeManager;
}
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;
}
public Map<String, Object> getMap() {
  return map;
}
public void setMap(Map<String, Object> map) {
  this.map = map;
}

/**
 * @Title: getNoticesByUserId 
 * @Description: TODO(獲取首頁顯示的所有公告數(shù)據(jù)) 
 * @return??? 設定文件
 * @return String??? 返回類型
 * @throws
 */
public String getNoticesByUserId() {
  // 存放數(shù)據(jù)的list
  List<ANotice> aNotices = new ArrayList<ANotice>();
  User u = (User) getSession().get("LoginUser");
  List<Notice> notices = noticeManager.GetNotices(page, rows, u.getId());

  for (Notice notice : notices) {
    ANotice aNotice = new ANotice();
    aNotice.setId(notice.getId());
    aNotice.setTitle(notice.getTitle());
    aNotice.setCreateDate(notice.getCreateDate());
    aNotice.setUserName(u.getUsername());
    aNotice.setContent(notice.getContent());
    aNotices.add(aNotice);
  }

  // total是easyui分頁工具的總頁數(shù)。名字固定。
  map.put("total", noticeManager.getTotal(page, rows, u.getId()));
  map.put("rows", aNotices);

  return SUCCESS;
}

// total是easyui分頁工具的總頁數(shù)。名字固定。
map.put("total", noticeManager.getTotal(page, rows, u.getId()));
map.put("rows", aNotices);

/********************2.Manager代碼*******************/
@Override
public List<Notice> GetNotices(int page, int rows, int userId) {    
  String hql="From Notice Where 1=1 and userId = ?";
  return dao.find(hql, new Object[]{userId}, page, rows);   
}

@Override
public Long getTotal(int page, int rows, int userId) { 
  String hql="select count(*) from Notice Where 1=1 and userId = ?";
  return dao.count(hql, new Object[]{userId});
}

/********************3.dao代碼*******************/
public List<T> find(String hql, Object[] param, Integer page, Integer rows) {
  if (page == null || page < 1) { 
    page = 1; 
  }
  if (rows == null || rows < 1) {
    rows = 10; 
  } 
  Query q = this.getCurrentSession().createQuery(hql); 
  if (param != null && param.length > 0) { 
    for (int i = 0; i < param.length; i++) { 
      q.setParameter(i, param[i]); 
    } 
  } 
  return q.setFirstResult((page - 1) * rows).setMaxResults(rows).list(); 
}

6.struts配置文件

<前后臺通過Json方式傳輸數(shù)據(jù) -->
<package name="jsonPackage" extends="struts-default,json-default">
  <action name="getNoticesByUserId" class="NoticeAction" method="getNoticesByUserId">
    < 返回json類型數(shù)據(jù) -->
    <result name="success" type="json">
      <param name="root">map</param>
    </result>
  </action>
</package>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持綠夏網(wǎng)。


UI

主站蜘蛛池模板: 体现汉字的歇后语| 疯狂 电影| a和b生的孩子是什么血型 | 欧美日韩欧美| 马路虫子图片| 女人香韩国电影| 电视剧《反击》主要演员| 日本电车系列| 台湾早期经典怀旧内衣模特走秀 | 冒险王2| 结婚四年未见面,军官老公回来了| 女人的战争剧情介绍| 陕09j01图集| 电影频道直播| 张月个人资料| 尹海英| 古诗改编版搞笑大全| 女公安毛片免费观看| 斓曦个人简介| 王若麟| 满天星的电影都有哪些| 特级做a爰片毛片免费看108| 红灯区观看| 郑乙永| 长靴靴虐视频vk| 天国恩仇| 觉醒年代免费看| 蝴蝶视频在线观看| cuba直播在哪个平台看| 以下关于宏病毒说法正确的是| 嗯~啊~快点死我男男视频| 想想办法吧爸爸| 季芹| 左耳演员表| 动物园作文| cctv16体育频道直播| 单敬尧| 大国医 电视剧| 新人类男友会触电电视剧免费观看全集 | 贝利亚头像,权威| 容易失禁的女仆桃乃木香奈|

!!!站長長期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103