制表符日期格式 [英] Tabulator date formatting

查看:172
本文介绍了制表符日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个名为Tabulator的库,它允许你做的一件事是在数据被推入表格时编辑数据。

I am using a library called Tabulator, and one of the things it allows you to do is to edit the data while it is being pushed into the table.

我们使用的日期使用长日期格式,如下所示: 2018-07-24T04:00:00.000Z 。我在表格中使用formatter使它看起来像这样: 2018-07-24 。这只是切割字符串。

Dates we use use long-date format and look something like this: 2018-07-24T04:00:00.000Z. I use formatter within the table to make it look like this : 2018-07-24. Which simply slices the string.

问题是 - 当有人试图下载pdf文件时,它仍然以长格式显示日期 - 这需要修复。我尝试过Tabulators官方网站显示的所有方式,对我来说没什么用。我似乎无法弄清楚这样做的正确方法,也许有人在这里有一些经验并可以与我分享?仅供参考格式化,如下所示:

The problem is - when someone is trying to download pdf file it still shows the date in the long format - this needs to be fixed. I tried all the ways that Tabulators official website shows, and nothing work for me. I can't seem to figure out the proper way of doing it, perhaps someone here had some experience here and can share it with me? Just for reference formatter looks like this:

{
    title: "Due",
    field: "duedate",
    width: 80,
    formatter: function (cell, formatterParams) {
        var toRet = 'No Date';
        if (cell.getValue() != null) toRet = cell.getValue().slice(0, 10)
        return toRet;
    }
}

基本上我需要相同的逻辑 - 获取单元格值下载时将其切片,或者在数据被推入表格时将其切片并省略格式化程序。

Essentially I need the same logic - get the cell value and slice it when downloading, or perhaps do it while data is getting pushed into the table and omit formatters all together.

PS我知道我可以在推送数据和切片必需字段之前迭代数组,但是正在寻找更优雅的解决方案。

P.S I understand I can just iterate through array before pushing the data and slice required fields, but was looking for more elegant solution.

推荐答案

只要您使用的是3.4或更高版本,就可以使用下载访问器为您执行此操作:

As long as your are using version 3.4 or higher you can use a download accessor to do that for you:

{
    title: "Due",
    field: "duedate",
    width: 80,
    accessorDownload : function (value, data, type, params, column) {
        var toRet = 'No Date';
        if (value != null) toRet = value.slice(0, 10)
        return toRet;
    }
}

它将在数据加载到数据时对其进行转换下载扩展

It will transform the data as it is loaded into the download extension

这篇关于制表符日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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