• 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>
  • 相关阅读:
    head命令
    less命令
    解决get方法传递URL参数中文乱码问题
    The method convert(String) of type DateConverter must override a superclass method
    Tomcat Can't load AMD 64-bit .dll on a IA 32
    聚合函数查询 group by having
    string[] 清理重复+反转显示
    C# GetValueList 获得字符串中开始和结束字符串中间得值列表
    C# GetValue 正则获取开始结束代码
    string [] 去除重复字符两个方法
  • 原文地址:https://www.cnblogs.com/yushouling/p/4800768.html
Copyright © 2020-2023  润新知