Как вы сортируете даты по времени в jQGrid? Я посмотрел документацию , в которой говорится, что я должен использовать функцию "AmPm". Тем не менее, я все еще не могу выполнить сортировку при учете AM / PM, особенно в поле «Дата входа» .
<!DOCTYPE HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My First Grid</title>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/redmond/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8/css/ui.jqgrid.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8/js/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8/js/jquery.jqGrid.min.js"></script>
<script type="text/javascript">
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
</script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#list1").jqGrid({
url: 'login-history.xml',
datatype: "xml",
mtype: "GET",
colNames:["Role","Member Name","Login Date","Logout Date","Duration"],
colModel:[
{name:"Role",width:220, xmlmap:"Role"},
{name:"Member Name",width:120, xmlmap:"MemberFullName"},
{name:"Login Date", width:150,xmlmap:"LoginDateTime", sorttype: "date", datefmt: "m/d/Y h:i AmPm" },
{name:"Logout Date", width:140,xmlmap:"LogoffDateTime", formatter:'date', formatoptions:{ srcformat:'m/d/Y h:i:s', newformat:'Y-m-d h:i:s' }, sorttype: "date", datefmt: "m/d/Y h:i:s" },
{name:"Duration", width:80,xmlmap:"DurationInMins", sorttype: "date", datefmt: "h:i"}],
rowNum:25,
rowList:[25,50,100,500],
viewrecords: true,
loadonce: true,
sortable: true,
altRows:true,
height: "100%",
pager: jQuery('#pager'),
hidegrid: false,
xmlReader: {
root : "DataSet",
row: "Participant",
repeatitems: false,
},
caption: "Login History"
});
jQuery("#list1").jqGrid('navGrid','#pager',{add:false,edit:false,del:false});
});
</script>
</head>
<body>
<table id="list1" class="scroll"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
</body>
</html>
Пример данных
<?xml version="1.0" encoding="UTF-8"?>
<DataSet>
<Participant>
<Role><![CDATA[Administrator]]></Role>
<Organization><![CDATA[Test Org]]></Organization>
<DurationInMins><![CDATA[46:44]]></DurationInMins>
<LogoffDateTime><![CDATA[09/30/2010 12:26:55]]></LogoffDateTime>
<LoginDateTime><![CDATA[09/30/2010 11:40 AM, PDT]]></LoginDateTime>
<MemberFullName><![CDATA[IBM Test]]></MemberFullName>
</Participant>
<Participant>
<Role><![CDATA[Administrator]]></Role>
<Organization><![CDATA[Test Org]]></Organization>
<DurationInMins><![CDATA[0:36]]></DurationInMins>
<LogoffDateTime><![CDATA[09/30/2010 01:40:53]]></LogoffDateTime>
<LoginDateTime><![CDATA[09/30/2010 01:40 PM, PDT]]></LoginDateTime>
<MemberFullName><![CDATA[IBM Test]]></MemberFullName>
</Participant>
<Participant>
<Role><![CDATA[Administrator]]></Role>
<Organization><![CDATA[Test Org]]></Organization>
<DurationInMins><![CDATA[16:39]]></DurationInMins>
<LogoffDateTime><![CDATA[09/22/2010 01:48:05]]></LogoffDateTime>
<LoginDateTime><![CDATA[09/22/2010 01:31 PM, PDT]]></LoginDateTime>
<MemberFullName><![CDATA[IBM Test]]></MemberFullName>
</Participant>
<Participant>
<Role><![CDATA[Administrator]]></Role>
<Organization><![CDATA[Test Org]]></Organization>
<DurationInMins><![CDATA[11:45]]></DurationInMins>
<LogoffDateTime><![CDATA[09/21/2010 08:29:02]]></LogoffDateTime>
<LoginDateTime><![CDATA[09/21/2010 08:17 AM, PDT]]></LoginDateTime>
<MemberFullName><![CDATA[IBM Test]]></MemberFullName>
</Participant>
<Participant>
<Role><![CDATA[Administrator]]></Role>
<Organization><![CDATA[Test Org]]></Organization>
<DurationInMins><![CDATA[45:35]]></DurationInMins>
<LogoffDateTime><![CDATA[09/15/2010 09:25:06]]></LogoffDateTime>
<LoginDateTime><![CDATA[09/15/2010 08:39 AM, PDT]]></LoginDateTime>
<MemberFullName><![CDATA[IBM Test]]></MemberFullName>
</Participant>
<Participant>
<Role><![CDATA[Administrator]]></Role>
<Organization><![CDATA[Test Org]]></Organization>
<DurationInMins><![CDATA[42:18]]></DurationInMins>
<LogoffDateTime><![CDATA[09/15/2010 12:56:29]]></LogoffDateTime>
<LoginDateTime><![CDATA[09/15/2010 12:14 AM, PDT]]></LoginDateTime>
<MemberFullName><![CDATA[IBM Test]]></MemberFullName>
</Participant>
<Participant>
<Role><![CDATA[Administrator]]></Role>
<Organization><![CDATA[Test Org]]></Organization>
<DurationInMins><![CDATA[5:45]]></DurationInMins>
<LogoffDateTime><![CDATA[09/15/2010 01:52:43]]></LogoffDateTime>
<LoginDateTime><![CDATA[09/15/2010 01:46 PM, PDT]]></LoginDateTime>
<MemberFullName><![CDATA[IBM Test]]></MemberFullName>
</Participant>
<Participant>
<Role><![CDATA[Administrator]]></Role>
<Organization><![CDATA[Test Org]]></Organization>
<DurationInMins><![CDATA[0:55]]></DurationInMins>
<LogoffDateTime><![CDATA[09/21/2010 08:16:42]]></LogoffDateTime>
<LoginDateTime><![CDATA[09/21/2010 08:15 AM, PDT]]></LoginDateTime>
<MemberFullName><![CDATA[IBM Test]]></MemberFullName>
</Participant>
<Participant>
<Role><![CDATA[Administrator]]></Role>
<Organization><![CDATA[Test Org]]></Organization>
<DurationInMins><![CDATA[0:49]]></DurationInMins>
<LogoffDateTime><![CDATA[09/07/2010 01:10:07]]></LogoffDateTime>
<LoginDateTime><![CDATA[09/07/2010 01:09 PM, PDT]]></LoginDateTime>
<MemberFullName><![CDATA[IBM Test]]></MemberFullName>
</Participant>
<Participant>
<Role><![CDATA[Administrator]]></Role>
<Organization><![CDATA[Test Org]]></Organization>
<DurationInMins><![CDATA[7:18]]></DurationInMins>
<LogoffDateTime><![CDATA[09/07/2010 01:17:39]]></LogoffDateTime>
<LoginDateTime><![CDATA[09/07/2010 01:10 PM, PDT]]></LoginDateTime>
<MemberFullName><![CDATA[IBM Test]]></MemberFullName>
</Participant>
</DataSet>