DataTables Ultimate日期/时间排序插件不能使用Intl格式 [英] DataTables Ultimate date / time sorting plug-in not working with Intl formats

查看:169
本文介绍了DataTables Ultimate日期/时间排序插件不能使用Intl格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ultimate日期/时间排序插件来排序日期列(



我错了吗?还是一个bug?这个插件在'en'locale'中正常工作

解决方案

似乎你使用终极日期/时间排序插件与文章中描述的不同。



columnDefs 选项使用以下代码:

  columnDefs:
{
targets:column_date,
render:function(data,type,full,meta){
if(type ==='显示'){
if(data){
var mDate = moment(data);
data =(mDate&& mDate.isValid())? mDate.format(LL):;
}
}

返回数据;
}
{
targets:column_time,
render:function(data,type,full,meta){
if(type == ='display'){
if(data){
var mDate = moment(data);
data =(mDate&& mDate.isValid())? mDate.format(L h:mm):;
}
}

返回数据;
}
},

我相信你可以删除以下行: / p>

  $。fn.dataTable.moment('LL',locale); 
$ .fn.dataTable.moment('L h:mm',locale);


I am trying to sort date columns using the Ultimate date / time sorting plug-in ( https://datatables.net/blog/2014-12-18 )

The columns are correctly displaying the into formatted dates, Invaded the datetime-moment.js file and as per the documentation , I added :

    $(document).ready(function() {  
         $.fn.dataTable.moment( 'LL', locale );
         $.fn.dataTable.moment( 'L h:mm', locale ); 

My DataTables default initialization is :

    $.extend( true, $.fn.dataTable.defaults, {
      dom: "<'row'<'col-xs-6'><'col-xs-6'f>r>t<'row'<'col-xs-6'l><'col-xs-6'p>>", 
      language: { url: langUrl },
      searching: true,
      ordering: true,
      paging: true,
      info: false,
      select: true
    } );

and the ColumnDefs, with the Intl date formats are :

     columnDefs:  {
           targets: column_date,
           type: 'date',
           render: function ( data, type, full, meta ) {
             if(data){
               var mDate = moment(data);
               return (mDate && mDate.isValid()) ? mDate.format("LL") : "";
             }
             return "";
           }
         },
         {
           targets: column_time,
           type: 'date',
           render: function ( data, type, full, meta ) {
             if(data){
               var mDate = moment(data);
               return (mDate && mDate.isValid()) ? mDate.format("L h:mm") : "";
             }
             return "";
           }
         },           

All data in these columns have this kind of values to be displayed :

         "Dernière Utilisation":"2015-09-21",
         "Dernière Connexion":"2015-09-21 15:24",

and I got correctly displayed , not sorted correctly

Am I wrong ? or is it a bug ? this plugin is working fine in 'en' locale'

解决方案

It seems that you're using Ultimate date/time sorting plug-in differently than described in the article.

Use the following code for the columnDefs option:

columnDefs:  
     {
       targets: column_date,
       render: function ( data, type, full, meta ) {
          if(type === 'display'){
             if(data){
                var mDate = moment(data);
                data = (mDate && mDate.isValid()) ? mDate.format("LL") : "";
             }
         }

         return data;
       }
     },
     {
       targets: column_time,
       render: function ( data, type, full, meta ) {
         if(type === 'display'){
            if(data){
               var mDate = moment(data);
               data = (mDate && mDate.isValid()) ? mDate.format("L h:mm") : "";
            }
         }

         return data;
       }
     },

I believe you can remove the following lines:

$.fn.dataTable.moment( 'LL', locale );
$.fn.dataTable.moment( 'L h:mm', locale ); 

这篇关于DataTables Ultimate日期/时间排序插件不能使用Intl格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆