jqgrid datetime列以24小时格式排序 [英] jqgrid datetime column sorting in 24 hour format

查看:378
本文介绍了jqgrid datetime列以24小时格式排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  {$]我正在使用一个json对象,从spring MVC来使用json reader来填充jqgrid。 b $ brows:[
{
id:1,
startTime:3月4日08:00,
projectId:Proj_001 ,
customerId:Cust1,
divisionId:Div1
},
{
id:2,
startTime:3月5日15:00,
projectId:Proj_001,
customerId:Cust1,
divisionId:Div1
},
{
id:3,
startTime:4月14日22:00,
projectId:Proj_001,
customerId:Cust1,
divisionId:Div1
}
]
}

我需要排序


startTime


< blockquote>

列在2 4小时时间格式(如上面的json对象)。我试着做一些解决方法,但仍然无法成功。



jqgrid代码 -

  {name:'startTime',index :'startTime',width:90,align:left,sorttype:'datetime',datefmt:'M d,Y at h:i',sortable:true,editrules:{date:true}},

我不会在这里使用AM / PM符号。我在jqgrid.base.js中看到它使用AM / PM符号排序。任何人都可以在这方面说明一下吗?我无法找到任何jqgrid示例使用24小时时间格式的日期,将进行排序。先谢谢你。



我的jqgrid代码 -

  jq(function(){
jq(#testgrid)。jqGrid({
url:/ getall.html,
datatype:'json',
mtype:'GET',
colNames:['Id','开始时间','Cust.Id','Div.Id','Proj.Id'],
colModel:[
{name:'id' index:'id',width:90,align:left,hidden:true},
{name:'startTime',index:'startTime',width:90,align:left,
sorttype:'datetime',datefmt:'M dh:i',sortable:true,
editrules:{date:true}},
{name:'divisionId',index:'divisionId' ,width:100,align:left},
{name:'departmentId',index:'departmentId',width:120,align:left},
{name:'projectId' ,index:'projectId',width:100,align:left},
],
pager:'#testpager',
loadonce:true,
sortnam e:'projectId',
sortorder:'asc',
viewrecords:true,
multiselect:true,
//隐藏寻呼机按钮
pgbuttons:
recordtext:'',
pgtext:'',
gridview:true,
caption:'my JQGRID',
jsonReader:{
root: rows,
page:page,
total:total,
records:records,
repeatitems:false,
cell:cell ,
id:id
}
});
//工具栏搜索
//jq(\"#testgrid\").jqGrid('filterToolbar',
// {stringResult:true,searchOnEnter:false});
});


解决方案

当我尝试重现你的问题,似乎工作正常。请参阅此处的演示。如果您按照开始时间列进行排序,所有的工作都没有任何问题,我可以看到。


I am using a json object as follows from spring MVC to populate the jqgrid by using a json reader.

{
    "rows": [
        {
            "id": 1,
            "startTime": "Mar 4 08:00",
            "projectId": "Proj_001",
            "customerId": "Cust1",
            "divisionId": "Div1" 
        },
        {
            "id": 2,
            "startTime": "Mar 5 15:00",
            "projectId": "Proj_001",
            "customerId": "Cust1",
            "divisionId": "Div1" 
        },
        {
            "id": 3,
            "startTime": "Apr 14 22:00",
            "projectId": "Proj_001",
            "customerId": "Cust1",
            "divisionId": "Div1" 
        } 
    ]
}

I need to sort the

startTime

column which comes in 24hour time format (as above in the json object). i tried do some workaround but still unable to succeed.

jqgrid code -

{name:'startTime', index:'startTime', width:90,align:"left",sorttype:'datetime',datefmt:'M d, Y at h:i',sortable: true,editrules:{date:true} },

i will not using AM/PM notation here. i saw in jqgrid.base.js it uses AM/PM notation to sort. can anyone please shed some light on this? i was unable to find any jqgrid example for using date with 24hour time format that will do sort. Thank you in advance.

my jqgrid code -

jq(function(){
    jq("#testgrid").jqGrid({
        url:"/getall.html",
        datatype: 'json',
        mtype: 'GET',
        colNames:['Id','Start Time','Cust.Id','Div.Id','Proj.Id'],
        colModel :[
            {name:'id', index:'id', width:90,align:"left",hidden: true},
            {name:'startTime', index:'startTime', width:90, align:"left",
             sorttype:'datetime', datefmt:'M d h:i',sortable: true,
             editrules:{date:true}},
            {name:'divisionId', index:'divisionId', width:100,align:"left"},
            {name:'departmentId', index:'departmentId', width:120,align:"left"},
            {name:'projectId', index:'projectId', width:100,align:"left"},
        ],
        pager: '#testpager',
        loadonce: true,
        sortname: 'projectId',
        sortorder: 'asc',
        viewrecords: true,
        multiselect: true,
        //to hide pager buttons
        pgbuttons:false,
        recordtext:'',
        pgtext:'',
        gridview: true,
        caption: 'my JQGRID',
        jsonReader : {
            root: "rows",
            page: "page",
            total: "total",
            records: "records",
            repeatitems: false,
            cell: "cell",
            id: "id"
        }
    });
    //toolbar search
    //jq("#testgrid").jqGrid('filterToolbar',
    //                       {stringResult:true,searchOnEnter:false});
});

解决方案

As I try to reproduce your problem all seems working correct. See the demo live here. If you will sort by the "Start Time" column all work without any problem which I could see.

这篇关于jqgrid datetime列以24小时格式排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆