考勤系統——程式碼分析datagrid

來源:互聯網
上載者:User

標籤:斑馬線   輕量   nbsp   ado   and   super   order   json格式   排序   

datagrid是easyui的控制項,DataGrid以表格形式展示資料,並提供了豐富的選擇、排序、分組和編輯資料的功能支援。DataGrid的設計用於縮短開發時間,並且使開發人員不需要具備特定的知識。它是輕量級的且功能豐富。儲存格合并、多欄位標題、凍結列和頁尾只是其中的一小部分功能。

建立:以table標籤建立

<table id="dg" style="width:1100px"></table>

通過jQuery建立datagrid,並添加列。

$("#dg").datagrid({        url:"KaoqinbiaozhunSelect",        // 定義列        columns:[[                {field:‘id‘,title:‘序號‘,width:100},                 {field:‘shangban‘,title:‘上班時間‘,width:100,sortable:true,                    formatter:function(value,row,index){                        valuee = getDate(value);                        return valuee;                    },                    },                 {field:‘xiaban‘,title:‘下班時間‘,width:100,                    formatter:function(value,row,index){                        valuee = getDate(value);                        return valuee;                    },                        },                {field:‘jidu‘,title:‘季度‘,width:100},                {field:‘chidao‘,title:‘遲到‘,width:100,                    formatter:function(value,row,index){                        return "超過"+value+"分鐘";                    },                    },                {field:‘kuanggong‘,title:‘曠工‘,width:100,                    formatter:function(value,row,index){                        return "超過"+value+"分鐘";                    },                },                {field:‘qiyongtype‘,title:‘啟用狀態‘,width:100,                    formatter:function(value,row,index){                        switch(value){                        case 1:return "啟用中...";break;                        case 2:return "未啟用";break;                        }                    },                    styler: function(value,row,index){                        if (value == 1){                            return ‘color:red;‘;                        }                    },                },                ]],

url指定Servlet,為資料來源,Servlet中調用後台邏輯方法,去查詢資料庫,返回資料。datagrid 接收的資料必須是json格式,可以通過封裝的形式封裝一個json便於資料庫查詢到的資料進行轉格式。

封裝json:

public class PageJSON<T> {    private int total = 0;    private List<T> rows = new ArrayList<T>();    public int getTotal() {        return total;    }    public void setTotal(int total) {        this.total = total;    }    public List<T> getRows() {        return rows;    }    public void setRows(List<T> rows) {        this.rows = rows;    }    public PageJSON(int total, List<T> rows) {        super();        this.total = total;        this.rows = rows;    }    public PageJSON() {        super();    }

調用:

PageJSON<KqJiabanxinxi> pj = new PageJSON<KqJiabanxinxi>();        String rtn = "{\"total\":0,\"rows\":[]}";        int total = new JiabanxinxiDao().getTotalall(map);        if(total>0){            List<KqJiabanxinxi> list = new JiabanxinxiDao().getPageListKQ(page, rows,map,sort);            pj.setTotal(total);            pj.setRows(list);            rtn = JSONObject.toJSONString(pj);        }        return rtn;

datagrid接收到資料後就會在資料表中將資料顯示出來,列中 field:‘對應json的欄位名’

其它屬性:

     striped:true,  // 斑馬線效果        rownumbers:true,       // 顯示行號        pagination:true,      // 顯示分頁欄        pageList:[4,8], // 每頁行數挑選清單        pageSize:4,        // 初始每頁行數        remoteSort:true,        sortName:‘id‘,        sortOrder:‘desc‘,

可以在datagrid資料表中添加按鈕,toolbar的形式添加:

toolbar:[            {iconCls:‘icon-search‘,text:‘查詢‘,handler:function(){                var f = $("#form2").serialize();                $("#dg").datagrid({url:"KaoqinbiaozhunSelect?"+f}).datagrid(‘load‘)},},            // 添加            {iconCls:‘icon-add‘,text:‘添加‘,handler:function(){                type="add";                $("#id").textbox({readonly:false});                $("#form1").form(‘reset‘);                $("#saveBiaoZhun").dialog(‘open‘)            },},

在按鈕上也可以添加jQuery來進行功能的實現。

頁面展示:

 

考勤系統——程式碼分析datagrid

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.