zoukankan      html  css  js  c++  java
  • easyui datagrid 前后台代码

    @RequestMapping("datagrid")
    public void datagrid(Model model, @ModelAttribute BeanName bean, HttpServletRequest request, HttpServletResponse response) {
        bean.setOffset(bean.getRows() * (bean.getPage()-1) );//limit:start    
        DataGrid dataGrid = new DataGrid();
        dataGrid.setRows(service.selectList(bean));//list
        dataGrid.setTotal(service.selectListCount(bean));//list total count
        writeJson(response, dataGrid);//对象转换成json输出
    }
    
    public class DataGrid {
    
        private Long total = 0L;
        private List rows = new ArrayList();
        
        //setter...
        //getter...
    }
    
    /**
     * 将对象转换成JSON字符串,并响应回前台
     * 
     * @param object
     * @throws IOException
     */
    public void writeJson(HttpServletResponse response,Object object) {
        try {
            String json =  com.alibaba.fastjson.JSON.toJSONStringWithDateFormat(object, "yyyy-MM-dd HH:mm:ss");
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().write(json);
            response.getWriter().flush();
        } catch (IOException e) {
            log.debug(e.getMessage());
        }
    }
    
    
    //sql:
    select * from table_ 
    where 1=1 
    order by ${sort} ${order}  
    limit ${offset},${rows}
    
    
    /***js**/
    $(function(){
        dg2 = $('#dg2').datagrid({
            url : '/datagrid.action',
            //iconCls : 'icon-save',
            pagination : true,
            pagePosition : 'bottom',
            rownumbers : true,
            pageSize : 1,
            pageList : [ 20, 50, 100],
            fit : true,
            fitColumns : true,
            nowrap : true,
            border : true,
            idField : '',
            sortName : 'f.name',
            sortOrder : 'asc',
            singleSelect : true,
            columns : [ [ 
                 {field:'id',title:'详情',align:'center',30,
                     formatter:function(value,row,index){
                            return '<a href="#" onclick="openInfo(' + row.id + ')">详情</a>';
                     }
                 },            
               {field:'xbr.real_name',title:'姓名',align:'center',sortable:true,50,
                    formatter:function(value,row,index){
                        if(row.bean != null) 
                            return row.bean.realName;
                    }
                }
             ] ],
             onDblClickRow: function(rowIndex, row){
                 
             }
        });
    });
    
    <body>
        <table id="dg2"  title="我的列表" ></table>
    </body>
  • 相关阅读:
    PS转换图片——我教你
    通过Ajax——异步获取相关问题解答
    Spring的线程安全
    Spring MVC的工作机制
    Annotation的语法和使用
    Spring Bean的生命周期
    浅谈Spring
    Spring的事务管理
    行为型模式
    结构型模式
  • 原文地址:https://www.cnblogs.com/yushouling/p/4800768.html
Copyright © 2011-2022 走看看