Truncating repeater values?

advanced-prototyping

#1

Hi,

Some values in my repeater are too long to display entirely. I’d like to truncate the text if it exceeds a certain number of characters. Is there any way to do this?

Thanks!


#2

In your OnItemLoad handler on the repeater, you can find where you have “Set <widget> text to [[Item.Column0]]” and change it to [[Item.Column0.substr(0,16)]] and that should only copy in the first 16 characters.


#3

OnItemLoad

Case 1 - If length of [[Item.column]] >= n set text on (widget) to ‘[[Item.column.substr(0,n-3)]]…’

Case 2 - Else if true set text on (widget) to ‘[[Item.column]]’


#4

If you wanna get all fancy with it, then yeah…


#5

Yes. Yes I do…

:wink:


#6

Then you might want to make sure your .substr() call is zero-indexed… :wink:


#7

i can more do it more fancy.

use this ellipsis.rplib (53.5 KB) widget to add css ellipsis to a widget. you can name the widgets to elliptify “ellipsis” or change the target-name in the widget.

css ellipsis does only work on single-line.


#8

This is great! Thanks! Is there a way to add the ellipsis if the text does extend the character limit?


#9

In fact, there are a couple of solutions in this very thread already!


#10

the css applies when the space limit is reached. it is a property, not a function, it does not cause performance problems to apply it to all single-line repeater.item.text-inputs


#11

I see now! Thanks everyone!


#12

This was so helpful, THANK YOU! Brilliant on the -3 to keep it all at a consistent max length.

The only thing I had to tweak to get it work for me was, when setting up my condition, I didn’t see an option for ‘Length of item value’ (only ‘Length of variable value’ or ‘Length of widget value’ which OnLoad hasn’t been set yet) so I instead used:

Case 1 - ‘Value’ of [[item.column.length]] >= n set text on (widget) to ‘[[Item.column.substr(0,n-3)]]…’

Case 2 - Else if true set text on (widget) to ‘[[Item.column]]’

And it to worked! Thanks again :slight_smile:


#13

Hello, Could you screenshot the solution of this to me. I am not having any luck at this point. Also, does this solution have to be put on each cell or is there a global setup that can OnLoad apply this to all cells on a table.
thanks in advance


#14

This would be placed on the OnItemLoad event where you populate the data from the repeater onto widgets. Presumably you have a Set Text action that sets a widget to something like [[Item.column0]] (be default). Modify that expression with one of the ones above.


#15

Thank you for your feedback. I was able to get it to work to an extent. I have one other extension of this that maybe you could help me understand. I need to tooltip each of these cells that have been truncated and I need the tooltip to show the original string of text, not the truncated version. Currently the tooltip is pulling the truncated string so somehow I need to target the original text. Once I understand this method it will be applied to a product I am working on.

Any ideas? Let me know if that makes sense. I have attached the file if that helps.

Thanks so much for taking a look at this. tooltip truncation.rp (77.6 KB)


#16

Store the full text in the repeater dataset. The text is only truncated when you set it to the widget that should show the truncated text.

“This is a long string” is in your dataset in a column called Column0.

So if you want to show the full string you Set Text to [[Item.column0]]. To show the truncated string you Set Text to [[Item.column0.substring(0,8)]]… which would give you: “This is…” (or whatever truncation method you chose).

TL;DR: Store the full text. Only truncate it when it’s displayed.


#17

how would you set length of [[item.column]] I don’t see a length, I see length of widget value only


#18

You can’t set the length of a value, but you can either get the length or get part of it, which is what “substr” does.


#19

My mistake. I typed that incorrectly. I have my data truncating correctly so I am now trying to figure out the conditions that will read the string length and only truncate when character count is past 10.

Does that make sense? Any Ideas?

Thank you for your responses.


#20

Oh, sorry about that, I misread your comment.

If I’m understanding you correctly now, just add a condition for “value” and set the value as “[[item.column0.length]]”.