extjs基本例子

这是一个.js文件   
Ext.onReady(function() {
/*root  获取json的值   autoLoad  自动装载   fields需要的值*/
    var store = new Ext.data.JsonStore({
        url:'action/do_post.jsp?method=list',
        root:'rows',
        autoLoad:true,
        fields:['postId','content','title',{name: 'createDate'}]
    });
 
 
    // create the Grid               
    var grid = new Ext.grid.GridPanel({
        store: store,                  /*调用上面的对象*/
        columns: [                    /*显示的列*/
            {
                id       :'postId',        /*标示列*/
                header   : 'postId',    
                width    : 50,
                sortable : true,          /*可排序*/
                dataIndex: 'postId'    /*内连的字段*/
            },
            {
                header   : 'content',
                width    : 75,
                sortable : true,
                dataIndex: 'content'
            },
            {
                header   : 'title',
                width    : 75,
                sortable : true,
                dataIndex: 'title'
            }
            ,
            {
                header   : 'date',
                width    : 150,
                sortable : true,
                /*渲染这个方法,renderer一般加的就是方法,自己定的或者掉用的*/
                renderer : Ext.util.Format.dateRenderer('m-d-Y H:m:s'),   
                dataIndex: 'createDate'
            }
        ],
 
        height: 350,
        600,
        title: 'Array Grid'
       
    });
 
    // render the grid to the specified div in the page
    grid.render('grid-example');      /*对应前台的div      <div id="grid-example"></div>*/
});
 
/*对应的查询页面
// json
    final JSONObject results = new JSONObject();
    JSONArray results2 = new JSONArray();
//处理复杂数据  
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.registerJsonValueProcessor(Date.class, new DateJsonValueProcessorImpl());
 
if (method.equals("list")) {
        try {
            List<Post> post_list = genericService.list(Post.class, "ORDER BY createdate ASC");
            results2 = JSONArray.fromObject(post_list,jsonConfig);
            results.element("rows", results2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    out.print(results);
*/
原文地址:https://www.cnblogs.com/lixin890808/p/3092535.html