Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 来自MySQL sql查询的kendo ui网格日期格式_Php_Mysql_Datetime_Kendo Ui_Kendo Grid - Fatal编程技术网

Php 来自MySQL sql查询的kendo ui网格日期格式

Php 来自MySQL sql查询的kendo ui网格日期格式,php,mysql,datetime,kendo-ui,kendo-grid,Php,Mysql,Datetime,Kendo Ui,Kendo Grid,我在这里寻找过类似的问题,没有一个完全回答我的问题,无论是完整的,还是以我能理解的方式 我从MySQL数据库中检索一个表示日期时间的字符串值,即“2013年10月3日05:30:45PM”在数据库中表示为“20131003173045”。该值作为日期显示在剑道网格的“上次登录”列中。这些都包含在使用MVC框架的面向PHP的网页中 之前,我在SQL查询中应用了日期格式,将字符串从“20131003173045”更改为“2013年10月3日05:30:45PM”,但这在KendoGrid中显示为字符

我在这里寻找过类似的问题,没有一个完全回答我的问题,无论是完整的,还是以我能理解的方式

我从MySQL数据库中检索一个表示日期时间的字符串值,即“2013年10月3日05:30:45PM”在数据库中表示为“20131003173045”。该值作为日期显示在剑道网格的“上次登录”列中。这些都包含在使用MVC框架的面向PHP的网页中

之前,我在SQL查询中应用了日期格式,将字符串从“20131003173045”更改为“2013年10月3日05:30:45PM”,但这在KendoGrid中显示为字符串,这意味着11月的日期可以出现在10月的日期之前,4月的日期最先出现等等。这是可以理解的,不是所需的函数,特别是在尝试按此列排序时

呈现KendoGrid的页面的示例代码:

<div class="div1">
    <div>
        <table id="listGrid"></table>
    </div>
</div>

<script>
    $(function() {
        $("#grid").kendoGrid({
            scrollable: false,
            groupable: false,
            sortable: {
                mode: "multiple"
            },
            resizable: true,
            pageable: true,
            dataSource:
            {
                transport:
                {
                    read:  {
                        url: "<?= $site_url ?>Settings/Users/List",
                        dataType: "json"
                    },
                    parameterMap: function (model, operation) {
                        if (operation == "read") {
                            return model;
                        }                            
                        else if(model) {
                            return { "json" : kendo.stringify(model) };
                        }
                        else
                            return "";
                    }                    
                },
                pageSize: 20,
                serverPaging: true,
                serverSorting: true,
                sort: { field: "LastLogin", dir: "desc" },
                serverGrouping: true,
                serverAggregates: false,
                schema: {
                  total: "total",
                  data: "data",
                  groups: "groups"
                }
            },

            toolbar: [ { title: "", template:'<a class="k-button k-button-icontext k-grid-add" href="<?= $site_url ?>Settings/Users/Add/">Add New User</a>' }],
            columns: [
                //{field: "Id", width: "40px"},
                {field: "UserName", title: "Alias", width: "160px"},
                {field: "ForeName", title: "Forename", width: "100px"},
                {field: "SurName", title: "Surname", width: "160px"},
                {field: "Initials", width: "80px"},
                {field: "CrmId", title: "CRM ID", width: "100px"},
                {field: "Dept", title: "Department", width: "100px"},
                {field: "Position"},
                // Below is the field in question
                {field: "LastLogin", title: "Last Login", width: "160px"}, 
                {field: "BlockedStatus", title: "Status", width: "90px"},
                { title: "", template:'<a class="k-button k-button-icontext k-grid-edit" href="<?= $site_url ?>Settings/Users/Update/#: Id #">Edit</a>' }
            ]
        });
    });
</script>

$(函数(){
$(“#网格”).kendoGrid({
可滚动:false,
分组:false,
可排序:{
模式:“多个”
},
可调整大小:正确,
pageable:对,
数据源:
{
运输:
{
阅读:{
url:“设置/用户/列表”,
数据类型:“json”
},
parameterMap:功能(型号、操作){
如果(操作==“读取”){
收益模型;
}                            
else if(型号){
返回{“json”:kendo.stringify(model)};
}
其他的
返回“”;
}                    
},
页面大小:20,
对,,
对,,
排序:{field:“LastLogin”,dir:“desc”},
对,,
服务器聚合:false,
模式:{
总计:“总计”,
数据:“数据”,
组:“组”
}
},
工具栏:[{title:,模板:'}],
栏目:[
//{字段:“Id”,宽度:“40px”},
{字段:“用户名”,标题:“别名”,宽度:“160px”},
{字段:“名字”,标题:“名字”,宽度:“100px”},
{字段:“姓氏”,标题:“姓氏”,宽度:“160px”},
{字段:“缩写”,宽度:“80px”},
{字段:“CrmId”,标题:“CRM ID”,宽度:“100px”},
{字段:“部门”,标题:“部门”,宽度:“100px”},
{字段:“位置”},
//下面是讨论中的字段
{字段:“LastLogin”,标题:“Last Login”,宽度:“160px”},
{字段:“BlockedStatus”,标题:“Status”,宽度:“90px”},
{标题:,模板:'}
]
});
});
我已经研究了kendo.parseDate和kendo.toString,并将两者结合起来,但似乎没有任何效果;我要么得到“null”或“20131003173045”,要么页面没有加载

我不能更改数据库数据,我只能将其格式化为SQL查询的一部分,这是我最初所做的


我需要整个“20131003173045”字符串变为“2013年10月3日05:30:45PM”,并且仍然按照正确的时间顺序进行排序-我如何做到这一点,如果kendo.parseDate和kendo.toString是正确的工具,我做错了什么?

我建议实现一个
模式。解析
函数,将MySQL格式转换为
日期
对象,然后使用
列。格式化
对其进行格式化

模式将是:

schema  : {
    data  : "data",
    total : "total",
    groups: "groups",
    parse : function (d) {
        $.each(d.data, function (idx, elem) {
            elem.LastLogin = kendo.parseDate(elem.LastLogin, "yyyyMMddHHmmss");
        });
        return d;
    }
}
现在,用于打印日期的列定义将定义所需的
格式

{field: "LastLogin", title: "Last Login", width: "160px", format: "{0:dd MMM, yyyy hh:mm:sstt}" }}, 

谢谢你的回答;但是我无法让它为我工作-这与解析函数有关吗,因为我不明白(d)指的是什么?我将不得不接受这个答案并结束这个问题,因为我正被迫离开这个问题;我的上级在站点的MVC框架的一个单独部分中做了一个变通方法来管理SQL查询。从你以前的帖子和回答中,我确信这是可行的,我只是无法让它在我的特定情况下发挥作用。如果这不是处理此类情况的正确方法,我深表歉意,但这是我的第一个问题。
d
是从服务器接收的数据,即服务器发送的数据。然后,在该结构中,我使用jQuery
each
通过
data
数组的所有元素进行迭代。对于每个元素,我都使用您提到的格式解析接收日期,其中,
yyyy
表示年份,4位数字,
MM
表示日期,2位数字,
dd
表示月份的某一天,
HH
表示小时,24小时格式,
MM
ss
表示分钟和秒。