我正在努力在网格中正确显示日期时间字段。它显示为第一年' 2010-05-01 00:00:00 '而不是第一天' 01-05-2010 00:00:00 '。在mysql中,它是一个datetime字段。我尝试过从开发人员文档中获取的各种选项,但似乎没有任何效果。我已经发布了我的代码,如果有人能突出我的错误,我将不胜感激。感谢
jQWidgets v3.2.2(2014-Mar-21) Developer site
var source =
{
datatype: "json",
datafields: [
{ name: 'id', type: 'string'},
{ name: 'date', type: 'date'},
{ name: 'activity', type: 'string'},
{ name: 'user', type: 'string'},
{ name: 'item', type: 'string'}
],
cache: false,
id: 'id',
url: 'temp/rtvData.php',
updaterow: function (rowid, rowdata, commit) {
// synchronize with the server - send update command
var data = "update=true&FirstName=" + rowdata.FirstName + "&LastName=" + rowdata.LastName + "&Title=" + rowdata.Title;
data = data + "&EmployeeID=" + rowid;
$.ajax({
dataType: 'json',
url: 'temp/rtvData.php',
type: 'POST',
data: data,
success: function (data, status, xhr) {
// update command is executed.
commit(true);
}
});
}
};
var dataAdapter = new $.jqx.dataAdapter(source);
// initialize the input fields.
/* $("#activity").jqxInput({width: 150, height: 23});
$("#user").jqxInput({width: 150, height: 23});
$("#item").jqxInput({width: 150, height: 23}); */
var dataAdapter = new $.jqx.dataAdapter(source);
var editrow = -1;
// initialize jqxGrid
$("#jqxgrid").jqxGrid(
{
width: 740,
editable: true,
sortable: true,
filterable: true,
columnsresize: true,
columnsreorder: true,
source: dataAdapter,
pageable: true,
autoheight: true,
altrows: true,
theme: 'custom',
columns: [
{ text: 'id', editable: false, datafield: 'id', width: 90 },
{ text: 'date', editable: false, datafield: 'date', cellsformat: 'D', filtertype: 'date', filterable: true, width: 190},
{ text: 'Activity', editable: false, datafield: 'activity', width: 100 },
{ text: 'User', editable: false, datafield: 'user', width: 160 },
{ text: 'Box', editable: false, datafield: 'item', width: 'auto' },
/* { text: 'Edit', datafield: 'Edit', width: 90, sortable: false, filterable: false, columntype: 'button', cellsrenderer: function () {
return "Edit";
}, buttonclick: function (row) {
// open the popup window when the user clicks a button.
editrow = row;
var offset = $("#jqxgrid").offset();
$("#popupWindow").jqxWindow({ position: { x: parseInt(offset.left) + 60, y: parseInt(offset.top) + 60 }, theme: 'custom' });
// get the clicked row's data and initialize the input fields.
var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
$("#firstName").val(dataRecord.FirstName);
$("#lastName").val(dataRecord.LastName);
$("#title").val(dataRecord.Title);
// show the popup window.
$("#popupWindow").jqxWindow('open');
}
} */
]
});
rtvData.php
{
// SELECT COMMAND
$result = mysql_query($query) or die("SQL Error 1: " . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$act[] = array(
'id' => $row['id'],
'date' => $row['date'],
'activity' => $row['activity'],
'user' => $row['user'],
'item' => $row['item']
);
}
echo json_encode($act);
}
答案 0 :(得分:1)
可能是因为本地化。请查看本指南:
您的代码:
{ text: 'date', editable: false, datafield: 'date', cellsformat: 'D', filtertype: 'date', filterable: true, width: 190},
默认本地化成员
patterns: {
// long date pattern
D: "dddd, MMMM dd, yyyy",
...
好例子:
http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/localization.htm?web
/ edit 2014-08-24
我将如何解决问题:
我首先要确保SQL查询将返回一个 正确的日期格式。
SELECT DATE_FORMAT(datecolumn,%Y。%m。%d)AS NewDate FROM exampletable;
我喜欢使用ISO 8601 standard,因为它没有任何问题。 MySQL DATE_FORMAT上的一些信息。
现在确保已设置引用。 (客户本地化文件)
script type="text/javascript" src="localization.js">
http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/localization.js
现在只需要调整网格。 (本地化归属)
$("#jqxgrid").jqxGrid(
{
width: 740,
source: dataAdapter,
sortable: true,
filterable: true,
pageable: true,
theme: 'custom',
localization: getLocalization('de'),
columns: [
{ text: 'Datefield', datafield: 'date', columntype: 'NewDate', filtertype: 'date', width: 210, cellsalign: 'right', cellsformat: 'd' }
]
});