【发布时间】:2018-06-27 19:11:37
【问题描述】:
我正在使用 JqGrid() 来创建表格,
单击标题时,我正在对列进行排序。
当我点击标题时,它按字母顺序对行进行排序,但我的日期格式为20-Jan-2018,它按字母顺序对日期列进行排序。
当我使用$("#grid").tablesorter({dateFormat: "uk"});
它给出了相同的输出。
如何不按月名排序,不按字母排序?
这是我的代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/themes/redmond/jquery-ui.min.css">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.4/css/ui.jqgrid.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.4/jquery.jqgrid.min.js">
</script>
<script>
$(function () {
"use strict";
$("#grid").jqGrid({
defaults:{
autoWidth:true,
},
width:550,
colModel: [
{ name: "Item" },
{ name: "Purchase Date"},
],
data: [
{
id: 10,
"Item": "T-1234",
"Purchase Date": "20-Jun-18",
} ,
{
id: 20,
"Item": "T-1235",
"Purchase Date": "20-Feb-18",
} ,
{
id: 30,
"Item": "T-1236",
"Purchase Date": "21-Jan-18",
} ,
{
id: 40,
"Item": "T-1237",
"Purchase Date": "22-Mar-18",
} ,
]
});
});
$(document).ready(function()
{
$("#grid").tablesorter( {sortList: [1,0]} );
}
);
$("#grid").tablesorter({dateFormat: "uk"});
</script>
<style type="text/css">
.ui-jqgrid .ui-jqgrid-htable th div {
height:auto;
overflow:hidden;
padding-right:4px;
padding-top:10px;
position:relative;
vertical-align:text-top;
white-space:normal !important;
}
.container{
padding: 250px;
padding-left: 350px;
}
</style>
</head>
<body>
<div class="container">
<table id="grid"></table>
</div>
</body>
</html>
【问题讨论】: