数据表和IE8中按日期排序 [英] dataTables and sorting by date in IE8

查看:132
本文介绍了数据表和IE8中按日期排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dataTables 排序日期字段(有 {sType:日期} null 排序类型(只是将数据排序为纯文本字符串)在IE8中正常工作。



适用于IE 9和10,以及最新版本的Chrome,Safari,Firefox。此应用不适用于移动客户端,所以我没有在那里测试。 / p>

有没有什么特别的IE8,我需要研究?在IE8的JavaScript控制台上没有错误,所以我有点失望,在哪里查看 dataTables 文档,搜索SO,但尚未找到任何IE8特定的。



更新:



这是我用来初始化我的数据表的JavaScript。

  // sprv结果表
$(#sprv_report_table)。livequery(function(){$(this).dataTa ({
aoColumns:[{sType:date},null,null,null,null,{sType:date}],
iDisplayLength ,
sPaginationType:full_numbers
});}); 1

由于数据表代码已经应用于表,我可以排序其他列,我没有任何理由相信这个事件没有被触发 - 似乎很明显,它被浏览器触发

解决方案

尝试这样的一种:

 code> $(this).dataTable({
aoColumns:[{
mData:function(data,type){
var realDate = Date.parse(data); //数据将是一个字符串
switch(type){
case'display':
return realDate.toString('MM / dd / yyyy'); //请注意,此行需要由您执行(但是格式化日期)
default:
return realDate;
}
}
},null,null,null,null,{sType:date}],
iDisplayLength:10,
sPaginationType:full_numbers
});

请参阅 mData a href =http://datatables.net/ref =nofollow> http://datatables.net/ref


整数 - 被视为数据源的数组索引。这是DataTables使用的默认值(每列逐渐增加)。



string - 从数据源读取一个对象属性。请注意,您可以使用Javascript点分法从数据源读取深层属性/数组。



null - 将为单元格使用sDefaultContent选项(默认为null)因此您需要指定所需的默认内容 - 通常为空字符串)。这可以在生成的列(如编辑/删除操作列)上有用。



函数 - 当DataTables需要设置或获取数据时,给定的函数将被执行对于列中的单元格。该函数有三个参数:
{array | object}数据源行
{string}请求的类型调用数据 - 设置数据或过滤器时显示set ','type','sort'或未定义时收集数据。请注意,如果为DataTable类型提供了未定义,则可以将该对象的原始数据返回给



{*}第二个参数为'set'。



当set是调用类型时,函数的返回值不是必需的,但否则返回值将用于数据



Having some trouble having dataTables sort date fields (which have {"sType":"date"}. The null sorting type (which just sorts the data as if it's a plain string) works fine in IE8.

Works in IE 9 & 10, as well as latest versions of Chrome, Safari, Firefox. This app is not used on mobile clients, so I didn't test it there.

Is there something special about IE8 that I need to be looking into? There are no errors on the JavaScript console in IE8, so I'm a little stumped as to where to look. Checked the dataTables docs and search around SO, but have yet to find anything IE8-specific.

UPDATE:

Here's the JavaScript I'm using to initialize my datatable.

//sprv results table
$("#sprv_report_table").livequery(function(){$(this).dataTable({
  "aoColumns": [{"sType":"date"},null,null,null,null,{"sType":"date"}],
  "iDisplayLength": 10, 
  "sPaginationType": "full_numbers"
});});1

Since the datatables code does get applied to the table, and I can sort other columns, I don't have any reason to believe that this event isn't getting fired - it seems rather obvious that it is being fired by the browser.

解决方案

Try something like this:

$(this).dataTable({
  "aoColumns": [{
    mData: function(data, type) {
       var realDate = Date.parse(data); //data will be a string
       switch(type) {
         case 'display':
            return realDate.toString('MM/dd/yyyy'); //note that this line needs to be implemented by you (however you format dates)
         default:
            return realDate;
       }
    }
   },null,null,null,null,{"sType":"date"}],
  "iDisplayLength": 10, 
  "sPaginationType": "full_numbers"
});

See reference on mData usage here: http://datatables.net/ref

integer - treated as an array index for the data source. This is the default that DataTables uses (incrementally increased for each column).

string - read an object property from the data source. Note that you can use Javascript dotted notation to read deep properties / arrays from the data source.

null - the sDefaultContent option will be used for the cell (null by default, so you will need to specify the default content you want - typically an empty string). This can be useful on generated columns such as edit / delete action columns.

function - the function given will be executed whenever DataTables needs to set or get the data for a cell in the column. The function takes three parameters: {array|object} The data source for the row {string} The type call data requested - this will be 'set' when setting data or 'filter', 'display', 'type', 'sort' or undefined when gathering data. Note that when undefined is given for the type DataTables expects to get the raw data for the object back

{*} Data to set when the second parameter is 'set'.

The return value from the function is not required when 'set' is the type of call, but otherwise the return is what will be used for the data requested.

这篇关于数据表和IE8中按日期排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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