VolkovLabs / business-text

The Business Text panel plugin allows you to construct a text visualization template from the values of a dataset returned by a data source query.
https://volkovlabs.io
Apache License 2.0
83 stars 13 forks source link

Sum a value to @index variable #234

Closed Yoslandy closed 1 year ago

Yoslandy commented 1 year ago

Hi Team.

Im trying to sum a value to the @index variable in this wonderful plugin. Especially sum 1 to the variable to show an order.

Example image

to show this (Just starting the table)

image

I would like, instead shows Lot 0, Lot 1,... that starts from Lot 1, Lot 2,... to not create confusion to the cliente.

Is there any way to do that? (I tried but give me errors like is not permited)

Thanks so much again and in advance

samant-rags commented 1 year ago

You can use handlebar helper functions and pass the @index as parameter to it and do any operation on it.

Handlebar helper function approach is in the documentation of dynamic text

handlebars.registerHelper("replace", (context, pattern, replacement) => context.replace(pattern, replacement) );

mikhail-vl commented 1 year ago

@samant-rags Thank you for the help.

@Yoslandy Here is how it looks like:

Content:

{{#each data}}
Index {{inc @index}}<br/>
{{/each}}

JavaScript:

handlebars.registerHelper("inc", (value) => parseInt(value)+1);

Screenshot 2023-11-19 at 8 33 51 PM