EXT gridpanel page

Source: Internet
Author: User

Grid. js

Ext. onready (function () {var gridstore = new Ext. data. store ({Proxy: New Ext. data. httpproxy ({URL: 'grid. ASP '}), Reader: New Ext. data. jsonreader ({root: 'data', totalproperty: 'totalcount', idproperty: 'id'}, [{Name: 'id', mapping: 'id'}, {Name: 'name', mapping: 'name'}, {Name: 'email ', mapping: 'email'}, {Name: 'age', mapping: 'age'},]), baseparams: {start: 0, limit: 5}); gridstore. load (); var colmodel = new Ext. grid. columnmodel ([{ID: 'userid', header: 'user No. ', dataindex: 'id', sortable: True, hidden: true}, {header: 'name', dataindex: 'name', sortable: True, width: 80}, {header: 'mailbox ', dataindex: 'email', width: 150}, {header: 'age', dataindex: 'age', width: 60},]); var gridpanel = new Ext. grid. gridpanel ({ID: 'oppanel ', Title: 'user information', frame: True, // iconcls: 't104', border: True, columnlines: True, striperows: True, autoheight: True, store: gridstore, SM: New Ext. grid. rowselectionmodel ({singleselect: true}), CM: colmodel, collapsible: True, // plugins: oprrowexpander, loadmask: {MSG: 'loading user information list ...... '}, bbar: New Ext. pagingtoolbar ({store: gridstore, pagesize: 5, displayinfo: True, displaymsg: 'display records {0}-{1}, total records {2} ', emptymsg: 'No matching record found'}); var viewport = new Ext. viewport ({layout: "fit", items: gridpanel });});

Grid.html

<!DOCTYPE html>

Data. Java

package com.lin.model;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;import javax.persistence.Table;@Entity@Tablepublic class Data {@GeneratedValue(strategy=GenerationType.IDENTITY)@Idprivate int id;@Column(length=20)private String name;@Column(length=30)private String email;@Columnprivate int age;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getEmail() {return email;}public void setEmail(String email) {this.email = email;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public Data(int id, String name, String email, int age) {super();this.id = id;this.name = name;this.email = email;this.age = age;}public Data() {super();}}
Datadao. Java
package com.lin.dao;import java.util.List;import org.hibernate.Query;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Repository;import org.springframework.transaction.annotation.Transactional;import com.lin.model.Data;@Repositorypublic class DataDao {private SessionFactory sessionFactory;public SessionFactory getSessionFactory() {return sessionFactory;}@Autowiredpublic void setSessionFactory(SessionFactory sessionFactory) {this.sessionFactory = sessionFactory;}@Transactionalpublic List<Data> getPageData(int start, int limit) {Session session = sessionFactory.getCurrentSession();Query query = session.createQuery("from Data");query.setFirstResult(start);query.setMaxResults(limit);System.out.println("size ================ "+query.list().size());return query.list();}@Transactionalpublic int getTotal(){Session session = sessionFactory.getCurrentSession();Query query = session.createQuery("from Data");return query.list().size();}}

Gridaction. Java

package com.lin.action;import java.io.PrintWriter;import java.util.ArrayList;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletResponse;import net.sf.json.JSONObject;import org.apache.struts2.ServletActionContext;import org.springframework.beans.factory.annotation.Autowired;import com.lin.dao.DataDao;import com.lin.model.Data;import com.opensymphony.xwork2.ActionSupport;public class GridAction extends ActionSupport {@Autowiredprivate DataDao dao;private int start;private int limit;public int getStart() {return start;}public void setStart(int start) {this.start = start;}public int getLimit() {return limit;}public void setLimit(int limit) {this.limit = limit;}@Overridepublic String execute() throws Exception {HttpServletResponse response = ServletActionContext.getResponse();response.setContentType("text/json; charset=utf-8");PrintWriter pw = response.getWriter();List list = dao.getPageData(start, limit);Map<String,Object> map = new LinkedHashMap<String, Object>();map.put("totalCount", dao.getTotal());map.put("data",list);JSONObject json = JSONObject.fromObject(map);pw.append(json.toString());pw.flush();pw.close();return NONE;}}

Effect:


Database:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.