解决EasyUI的datagrid控件显示日期问题

来源:互联网 发布:linux查看当前进程 编辑:程序博客网 时间:2024/04/29 20:11

在做积分系统的时候,做的是后台管理系统,所以前段框架用的是EasyUI,使用datagrid的时候,后台返回来一个日期格式的数据,当json序列化后返回来的数据就变成了/Date(1419264000000)/

这里写图片描述

改前代码:

 <table id="dg" class="easyui-datagrid" style="width:auto;height:auto"            url="/QuestManage/LoadPageQuestIndex" toolbar="#tb"            title="题目信息表" singleSelect="false" fitColumns="true" iconCls="icon-save"                rownumbers="true" pagination="true" pagesize="10">            <thead>                <tr>                    <th data-options="field:'quesID',hidden:'true'" >题目ID</th>                    <th data-options="field:'quesContent'"style="width:20%">题目内容</th>                    <th data-options="field:'quesScore'"style="width:20%">题目分值</th>                    <th data-options="field:'quesTypeID'"style="width:20%">所属类别</th>                    <th data-options="field:'quesController'"style="width:20%">所用控件</th>                </tr>            </thead>         </table>

改后代码:

 <table id="dg" class="easyui-datagrid" ></table>        <script>            $('#dg').datagrid({                toolbar:tb,                url: '/QuestManage/LoadPage',                title: "课程信息",                singleSeletct: true,                fitColumns: true,                rownumbers: true,                pagination: true,                pagesize: 10,                columns: [[                        { field: 'quesTypeID', title: '编号', hidden: true },                        { field: 'quesType', title: '题型名称', width:40},                        {                            field: 'date', title: '添加时间',width:40,                            formatter: function (value, row, index) {                                return changeDateFormat(value)                            }                        },                        { field: 'operater', title: '操作人', width:25 },                        { field: 'userLevel', title: '所属部门', width: 60 }                ]]            });            //转换日期格式              function changeDateFormat(cellval) {                if (cellval != null) {                    var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));                    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;                    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();                    return date.getFullYear() + "-" + month + "-" + currentDate;                }            }</script>

效果图:
这里写图片描述

简单的做一个记录,以后遇到类似的问题,有地方找,这几天有一个很深刻的体会,如果一个问题迟迟没有解决,那就放下半天或者一天,你在解决的时候有很大的几率你会利用很短的时间解决

阅读全文
0 0
原创粉丝点击