最近公司有个需求,需要根据检查单,获取数据列表,再将数据列横向排布作为grid的列,即动态列。
思路:Exjts的gridpanel有个方法grid.reconfigure(store, json.fieldheader),我们可以通过这个方法传递column和store,而store必须有data和fields,所以我们的目的是从后台获取三个对象:1、fields 2、data 3、header(表头)
思路有了,那就看如何实现,后台代码我已经把备注都写了,自己看
/**
* @功能描述:动态列
*/
public ActionForward getDynamicColumn(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setContentType("text/json;charset=utf-8");
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(Date.class,
new JsonDateValueProcessor());
Session session = null;
Transaction tx = null;
String checkNameId=request.getParameter("checkNameId"); //检查名称id
try {
session = HibernateClass.getSession();
tx = session.beginTransaction();
Query sq=session.createSQLQuery("select distinct t1.checksubitem from t_pm_projectcheck t,t_pm_projecteval t1 where t.id=t1.parentid and t.checknameid='"+checkNameId+"'");
List queryList=sq.list();
/*思路:1、获取表头*/
String[] header=getHeader(checkNameId,queryList);
/*如果表头个数不大于4(即扣除行号、项目名称、项目经理、总分4列),则返回空*/
if(header.length>4){
/*2、获取store的field内容*/
String[] fieldsInArray=getFieldsInArray(checkNameId,queryList);
/*3、获取store的data内容,即数据*/
String[][] content = this.getTableContent(checkNameId,queryList,session,header.length,fieldsInArray);

这篇博客介绍了如何在Extjs4中根据需求动态创建grid的列。通过使用grid.reconfigure方法,结合后台返回的fields、data和header对象,实现了动态列显示的功能。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



