问题
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