Get Free Trial

Prevent auto-formatting on cells with type ‘header’

Denis asked on March 23, 2021


At the moment we have columns of the time type and from the backend the time comes in milliseconds.

There is a need to change the milliseconds to a decimal time format from the backend like hh.00. We ran into a problem during these changes. We apply our own formatting to the time in the pivot table using customizesell. For cells with type `value` there are no problems, we convert the decimal time format to the one we need, but for cells with type `header` we cannot do this, due to the fact that the date.label already contains a value converted into a timePattern. Apparently the flexmonster automatically converts header-type time cell into the specified timePattern format, and because it waits for milliseconds there, and the decimal format time comes, it converts it incorrectly and already in customization we cannot apply the required format with data.label (wrong format number here).

The question is, is there any way to disable the automatic time conversion for the header cells so that we can do it ourselves in a customizecell?

If this is not possible, there is a backup plan in the form of changing the time type to some custom one, which flexmonster does not support and will not automatically format, or probably not to custom type, but to number type and with some flag isTime for example to track when we need to format it to time on the table and charts. Are there any pitfalls in this changing and what is the best type for this case?

Regards, Denis

3 answers

Illia Yatsyshyn Illia Yatsyshyn Flexmonster March 23, 2021

Hello, Denis,
Thank you for reaching out to us.
If we understand correctly, you pass the field of the time data type represented as milliseconds and format it using the customizeCell API call. Still, you specify the data type of the field as time in the mapping object. This is why header cells are automatically converted to the defined timePattern and cannot be formatted using your custom function.
We have described this scenario in the following JSFiddle for a better understanding:
If the described scenario is correct, we suggest using one of the following approaches:
Convert milliseconds to seconds on your backend and pass it to Flexmonster. Next, use the timePattern to apply the desired formatting both to value and header cells. Please specify the field’s data type as time to use this approach.
In case using the built-in time formatting is not an option for some reasons, we recommend changing the data type of the time field to number. Next, use the field’s uniqueName to identify whether it needs formatting by the customizeCell hook’s capabilities. The field’s uniqueName property will serve as an isTime flag you mentioned in your question.
We understand that it is not possible to permanently store all the time fields’ unique names on the client-side. As a workaround, it is possible to use a naming convention (e.g., a unique name must contain “time”) or send the preflight request that would return these unique names.
Still, the most convenient approach is to use the built-in time formatting as described above. We highly recommend using this way instead.
Please let us know if it works for you.
Kind regards,

Illia Yatsyshyn Illia Yatsyshyn Flexmonster March 31, 2021

Hello, Denis,
We are wondering if you had some time to check the provided solution.
Please let us know if it works for you.

Illia Yatsyshyn Illia Yatsyshyn Flexmonster April 7, 2021

Hello, Denis,
We are reaching out to ask if the proposed solution works for your case.
Feel free to contact us in case additional questions on this point arise.
Best regards,

Please login or Register to Submit Answer