jquery datatable为日期渲染函数

时间:2017-03-17 15:31:32

标签: jquery datatables

我正在使用jquery插件 - Datatable来渲染gridview并进行排序,搜索&分页。

我可以让它工作,除非我尝试渲染日期。没有任何渲染过滤器,我的日期在数据表中显示为

  

/日期(1489005452663)/

,日期作为日期和时间戳存储在数据库中

  

2017-02-14 15:52:02.177

当我在jquery中包含我的日期的渲染时,数据表不会填充任何内容并显示空白表。

以下是我用来填充数据表的代码:

$(document).ready(function() {
       $.ajax({
           url: 'ReportService.asmx/LoadReport',
           method: 'post',
           dataType: 'json',
           success: function(data) {
               $('#datatable').dataTable({
                   data: data,
                   columns: [
                       { 'data': 'CMS_CONTRACT_NUMBER' },
                       { 'data': 'submissionid' },
                       { 'data': 'file1status' },
                       { 'data': 'file2status' },
                       {
                         'data': 'datesubmitted',
                         'render': function (data)
                          {
                              var date = new Date(parseInt(data.substr(6)));
                              var month = date.getMonth() + 1;
                             return date.getFullYear() + "/" + month + "/" + date.getDate ;
                            //  return data;
                          }
                       }
                   ]
               });
           }
       });
   });

我不确定导致渲染包含的内容不会填充任何数据。

2 个答案:

答案 0 :(得分:2)

请确保通过括号括起来调用getDate方法:

return date.getFullYear() + "/" + month + "/" + date.getDate();
                                                         // ^

使用括号它应该有效:



var data = '/Date(1489005452663)/';
var date = new Date(parseInt(data.substr(6)));
var month = date.getMonth() + 1;
console.log(date.getFullYear() + "/" + month + "/" + date.getDate());




我们无法看到其他事情发生。当然,您也可以尝试使用不同的方法解析数字:



var data = '/Date(1489005452663)/';
var date = new Date(+data.replace(/\D/ig,""));
var month = date.getMonth() + 1;

console.log(date.getFullYear() + "/" + month + "/" + date.getDate());




答案 1 :(得分:0)

<html> <head> <title>A Floating Grid Item?</title> </head> <body> <div class="grid-container"> <p>Fake Lipsum - is that even a real thing? Lipsi lipsum lipsooo doo.</p> <figure> <img src="http://38.media.tumblr.com/3a8dee9aae420a0048907c54ff701fc8/tumblr_n8m6qv50X11r238sko1_500.jpg" alt="A cat"> <figcaption>I want the paragraph(s) below to flow around this box.</figcaption> </figure> <p>I want this to flow around the image. Please?</p> <p>It would be great if this would flow too, if it's not naturally below the image because of the amount of text.</p> <p>Again, it would be great if this would flow too, if it's not naturally below the image because of the amount of text.</p> <p>Yet again, it would be great if this would flow too, if it's not naturally below the image because of the amount of text.</p> </div> </body> </html>功能中使用此功能:

render