visibleItemCount


#1

I have a repeater that I’m applying filters to with buttons and I display the number of results. That all works fine.

But if there are no results then it doesn’t seem to update and stays at whatever it was before.

Any ideas?


#2

Hi!

I’m guessing that you are using On item Loaded to display the results. On Item Loaded runs once for each row in the repeater, so when there are no rows because they all got filtered out, it doesn’t run at all.

Instead put the code in the button that sets the filter:

On Clicked (of button)
  Set the filter
  Set text of whatever to [[LVAR_repeater.visibleItemCount]]

LVAR_repeater is a local variable referring to the repeater.

If you are filtering from multiple places and you want the repeater to deal with it automatically, you could put the repeater in a Fit to Content dynamic panel and say:

On Sized (of fit-to-content dynamic panel)
  Set text of whatever to [[LVAR_repeater.visibleItemCount]]

This works because the panel changes size when the repeater does. However, this works only for counting rows, as a differing row count is what would cause the panel to resize.

If you were summing the value of a column, for example, that sum might change even when the row count (and thus repeater size) stays the same. In that case, you’d handle the summing in On Item Loaded, and in the fit-to-content dynamic panel you’d handle the no-rows case.

On Sized (of fit-to-content DP)
  if [[This.height]] equals 0
    set text of sumLabel to 0

Note the condition above would also work for counting rows in the zero-rows case when you otherwise use Item Loaded to do the counting. Keep in mind that the minimum height of the repeater is its border width times 2. The condition above assumes the border width is 0.


#3

Nice one! Thanks for that, and for the one about pushing and pulling when a repeater is filtered. All working fine