问题:我将 ASP.NET gridview 更改为 SlickGrid。
到目前为止,它工作正常,我只是在日期格式方面遇到了一点问题。
我的 JSON 序列化测试数据如下所示:
[{
"title" : "Task 1",
"duration" : "5 days",
"percentComplete" : 47,
"start" : "\/Date(1230764400000)\/",
"finish" : "\/Date(1241128800000)\/",
"effortDriven" : false
},
{
"title" : "Task 2",
"duration" : "5 days",
"percentComplete" : 41,
"start" : "\/Date(1230764400000)\/",
"finish" : "\/Date(1241128800000)\/",
"effortDriven" : false
},
{
"title" : "Task 3",
"duration" : "5 days",
"percentComplete" : 42,
"start" : "\/Date(1230764400000)\/",
"finish" : "\/Date(1241128800000)\/",
"effortDriven" : true
},
{
"title" : "Task 100",
"duration" : "5 days",
"percentComplete" : 63,
"start" : "\/Date(1230764400000)\/",
"finish" : "\/Date(1241128800000)\/",
"effortDriven" : false
}]
这就是我使用 AJAX 加载数据的方式
<script type="text/javascript" language="javascript">
Date.prototype.getTicksUTC = function () {
return Date.parse(this.toUTCString()) + this.getUTCMilliseconds();
} // End Function getTicksUTC
function GetNavigationContent()
{
var filter = "nofilter" + new Date().getTicksUTC();
$.getJSON('/ajax/NavigationContent.ashx?filter=' + filter, function (data) {
grid = new Slick.Grid($("#myGrid"), data, columns, options);
grid.onSort = function (sortCol, sortAsc)
{
sortdir = sortAsc ? 1 : -1;
sortcol = sortCol.field;
if (sortAsc == true)
data.sort(compare);
else
data.reverse(compare);
grid.render();
}; // End Event onSort
}); // End Function getJSON
} // End Function GetNavigationContent
</script>
var columns = [
{ id: "title", name: "Title", field: "title", width: 120, cssClass: "cell-title" }
, { id: "duration", name: "Duration", field: "duration" }
, { id: "%", name: "% Complete", field: "percentComplete", width: 80, resizable: false, formatter: Slick.Formatters.PercentCompleteBar }
, { id: "start", name: "Start", field: "start", minWidth: 60 }
, { id: "finish", name: "Finish", field: "finish", minWidth: 60 }
, { id: "effort-driven", name: "Effort Driven", sortable: false, width: 80, minWidth: 20, maxWidth: 80, cssClass: "cell-effort-driven", field: "effortDriven", formatter: Slick.Formatters.Checkmark }
];
这是我的选择:
var options = {
editable: false,
enableAddRow: false,
enableCellNavigation: true
};
GetNavigationContent();
这是生成测试数据的 ajax 处理程序:
Imports System.Web
Imports System.Web.Services
Public Class NavigationContent
Implements System.Web.IHttpHandler, System.Web.SessionState.IRequiresSessionState
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "application/json"
Dim lsNavigationContent As New List(Of cNavigationRow)
Dim seed As Random = New Random
Dim nrThisNavigationRow As cNavigationRow = Nothing
For i As Integer = 1 To 100 Step 1
nrThisNavigationRow = New cNavigationRow
nrThisNavigationRow.title = "Task " + i.ToString()
nrThisNavigationRow.percentComplete = seed.Next(0, 100)
nrThisNavigationRow.effortDriven = DirectCast(IIf(i Mod 3 = 0, True, False), Boolean)
lsNavigationContent.Add(nrThisNavigationRow)
Next
Dim strJson As String = Tools.JSON.JsonHelper.Serialize(lsNavigationContent, False)
context.Response.Write(strJson)
End Sub
Public Class cNavigationRow
Public title As String = "Task 499"
Public duration As String = "5 days"
Public percentComplete As Integer = 9
Public start As DateTime = System.DateTime.Parse("01.01.2009", New System.Globalization.CultureInfo("de-CH", False))
Public finish As DateTime = System.DateTime.Parse("01.05.2009", New System.Globalization.CultureInfo("de-CH", False))
Public effortDriven As Boolean = False
End Class
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
问题是,这呈现如下(参见日期列):
如何最好地格式化日期列?
将其作为已格式化的字符串输入,还是有更好的方法,提供语言和/或格式代码?
如果我把它作为字符串放在那里,它将如何排序?