Formatting With kendo.toString() in Custom HTML Query

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
lachlan_so
Posts: 8
Joined: Mon Dec 02, 2019 3:32 am

Formatting With kendo.toString() in Custom HTML Query

Post by lachlan_so »

Hi everyone, I am trying to format every number in my query to 2 decimal places (including zeros) by using "kendo.toString({Attribute}, n2)". A few examples of what I should happen with the numbers are as follows:

1234.56 = 1,234.56
1234 = 1,234.00
1234.5 = 1,234.50

Does anyone have any idea how to do this? I have tried using a script tag in the html of the custom query and I have tried assigning a class to the areas I want the values to be displayed then modified the class with an initialisation script but neither seem to work and I still end up with numbers displaying as 1234.0.
customaware
Posts: 2413
Joined: Mon Jul 02, 2012 12:24 am
Location: Ulaanbaatar, Mongolia

Re: Formatting With kendo.toString() in Custom HTML Query

Post by customaware »

Why not just use a Number format of n instead of # ?
Cheers,
Mark
_________________
AwareIM 6.0, 8.7, 8.8, 9.0 , MariaDB, Windows 10, Ubuntu Linux. Theme: Default, Browser: Arc
Upcloud, Obsidian....
Image
lachlan_so
Posts: 8
Joined: Mon Dec 02, 2019 3:32 am

Re: Formatting With kendo.toString() in Custom HTML Query

Post by lachlan_so »

eagles9999 wrote: Mon Dec 21, 2020 5:46 am Why not just use a Number format of n instead of # ?
I've tried what I think you mean but it doesn't seem to do anything either. I think I might be misunderstanding how this is meant to work so I will supply some snippets to hopefully help convey what the problem is.

The last thing I tried was making a new query, changed it to display as a custom HTML query and placed a line like this in it:

Code: Select all

{Budget}
I then tried to modify the formatting with kendo.toString() to remove unneeded precision of the number in a user dashboard for ease of review (no need to know the number to 10 decimal places when you are just checking things for a rough idea of the situation, you can view it in full elsewhere). To do this I tried putting the toString() function in script tags in the hopes it would just display the output but that unfortunately didn't help.

I ended up putting the attribute inside a class that looks something like this:

Code: Select all

<div class="kendoBudget">{Budget}</div>
Then tried using an initialisation script (and later a render script) to grab all HTML elements with the "kendoBudget" class to use the innerhtml's current content as input for the toString() function then replacing the innerhtml of each element with the result of the toString() function. This didn't work either and even if it did would involve a lot of loops on a large number of objects that I would rather avoid if possible. I did however manage to get this idea to halfway work by assigning a span with an id then doing the same thing to that span. The problem with this is that ids can only be used once in HTML and therefore I was only able to modify the first line of the query, not all of them.

I think at some point I may have overcomplicated this whole thing but I really don't know. I have tried using a javascript alert to tell me how many elements with the class on them are in the html but the response back is always 0 which is confusing too since there should be hundreds if not thousands of records with that class attached to them (afterall I can read the original number in the query).

I just want a number like "123456.789" that is saved in an attribute at that precision to be displayed in a Custom HTML query as "123,456.79".
ACDC
Posts: 1146
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Re: Formatting With kendo.toString() in Custom HTML Query

Post by ACDC »

Have you tried this format: #,##0.00

If you set the format on the Object.Amount number attribute as above, this will work both in an HTML cell and a CUSTOM grid query
eg: <<Object.Amount>> or {Amount}
lachlan_so
Posts: 8
Joined: Mon Dec 02, 2019 3:32 am

Re: Formatting With kendo.toString() in Custom HTML Query

Post by lachlan_so »

ACDC wrote: Tue Dec 22, 2020 9:36 am Have you tried this format: #,##0.00

If you set the format on the Object.Amount number attribute as above, this will work both in an HTML cell and a CUSTOM grid query
eg: <<Object.Amount>> or {Amount}
This seems to work, I knew I must have been overthinking it, thanks!
ACDC
Posts: 1146
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Re: Formatting With kendo.toString() in Custom HTML Query

Post by ACDC »

I knew I must have been overthinking it, thanks!
Yeah , most often times when I get stuck it's because of overthinking and forgetting AwareIM is a simplified process, if its getting complex then you going the wrong way :D
Post Reply