jes*_*ges 68 date kendo-ui kendo-grid
我有一个KendoGrid类似下面,当我运行应用程序时,我没有得到date列的预期格式.
$("#empGrid").kendoGrid({
dataSource: {
data: empModel.Value,
pageSize: 10
},
columns: [
{
field: "Name",
width: 90,
title: "Name"
},
{
field: "DOJ",
width: 90,
title: "DOJ",
type: "date",
format:"{0:MM-dd-yyyy}"
}
]
});
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我2013-07-02T00:00:00Z在DOJ专栏中得到了" ".为什么不格式化?任何的想法?
aho*_*try 118
我找到了这条信息并使其正常工作.给我的数据是字符串格式,所以我需要kendo.parseDate在格式化之前解析字符串kendo.toString.
columns: [
{
field: "FirstName",
title: "FIRST NAME"
},
{
field: "LastName",
title: "LAST NAME"
},
{
field: "DateOfBirth",
title: "DATE OF BIRTH",
template: "#= kendo.toString(kendo.parseDate(DateOfBirth, 'yyyy-MM-dd'), 'MM/dd/yyyy') #"
},
...
Run Code Online (Sandbox Code Playgroud)
mig*_*lug 40
只需要将列的数据类型放在数据源中
dataSource: {
data: empModel.Value,
pageSize: 10,
schema: {
model: {
fields: {
DOJ: { type: "date" }
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后是你的陈述栏:
columns: [
{
field: "Name",
width: 90,
title: "Name"
},
{
field: "DOJ",
width: 90,
title: "DOJ",
type: "date",
format:"{0:MM-dd-yyyy}"
}
]
Run Code Online (Sandbox Code Playgroud)
gur*_*war 10
尝试将kendo网格中的日期格式化为:
columns.Bound(x => x.LastUpdateDate).ClientTemplate("#= kendo.toString(LastUpdateDate, \"MM/dd/yyyy hh:mm tt\") #");
Run Code Online (Sandbox Code Playgroud)
小智 10
这是使用ASP.NET的方法:
add .Format("{0:dd/MM/yyyy HH:mm:ss}");
@(Html.Kendo().Grid<AlphaStatic.Domain.ViewModels.AttributeHistoryViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.AttributeName);
columns.Bound(c => c.UpdatedDate).Format("{0:dd/MM/yyyy HH:mm:ss}");
})
.HtmlAttributes(new { @class = ".big-grid" })
.Resizable(x => x.Columns(true))
.Sortable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Model(model =>
{
model.Id(c => c.Id);
})
.Read(read => read.Action("Read_AttributeHistory", "Attribute", new { attributeId = attributeId })))
)
Run Code Online (Sandbox Code Playgroud)
我使用的选项如下:
columns.Bound(p => p.OrderDate).Format("{0:d}").ClientTemplate("#=formatDate(OrderDate)#");
function formatDate(OrderDate) {
var formatedOrderDate = kendo.format("{0:d}", OrderDate);
return formatedOrderDate;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
117408 次 |
| 最近记录: |