Tabulator date formatting

最后都变了- 提交于 2019-12-08 07:12:39

问题


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.

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.

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.

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.


回答1:


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



来源:https://stackoverflow.com/questions/51600815/tabulator-date-formatting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!