Hi,
I have one screen in that I have used multiple flex repeaters.
I want to do search functionality, What ever number entered in text field to search, It should get highlight.
here I am searching for 180 so 180 should be highlight in orange color.
I have tried by setting background color but it is not working.
Thanks.
I think we’re gonna need more details about how you search, and how you’re trying to change the background color.
I have one label which is I am using in flex repeater.
On background color property I am checking, If label text=searchLable(180) then set orange color else set green color
how are you filling up these flexrepeaters?
you can set the style of an instance of the flexrepeater in property
instances[x].instanceStyle
To flex repeater instances I am binding a tag(dataset).
Like this.
Add a viewproperty: self.view.params.search ?
then in the bindings you will have to add these to params (before appending it to instances):
if str(stopId) == str(self.view.params.search):
params['instanceStyle'] = {'backgroundColor':'orange'}
else:
params['instanceStyle'] = {'backgroundColor':'green'}
You could put something like this on the search button:
If the bindingss refresh really fast you wont need to do the forloop here just change the view.param (first 2 lines)
stringToFind = self.getSibling("TextField").props.text
self.view.params.search = str(stringToFind)
flexRepeaters = [self.getSibling("FlexRepeater"),self.getSibling("FlexRepeater_0")]
for x in flexRepeaters:
for inst in x.props.instances):
if (str(inst.stopId) == str(stringToFind)):
inst.instanceStyle['backgroundColor']='orange'
else:
inst.instanceStyle['backgroundColor']='green'
where I need to put this code, On background property of label?
this on the flexrepeaters
the other one on the search button assuming the search button is in the same view as the flexrepeaters
if you want to use it on the level of the labels you will have to bind the search text field to a custom session prop.
thatway the labels will be able to reach that prop too. But this should be done on the flexrepeater level for good practice (i guess)
Search button is on another view, through embedded view I am showing that view.
then you could use messages or just use the session prop i guess
The setting of params within a transform of the binding will not work, because those will only update or evaluate when the binding updates. You will indeed want to use either a Message Handler or a Session Property here.
Use an onChange script for your Text Field (or Numeric Entry Field).:
system.perspective.sendMessage('SEARCH', payload={"value": currentValue.value}, scope="page")
Then your Label should have a configured listener with the following code:
if float(payload["value"]) == float(self.props.text):
self.props.style.backgroundColor = "orange"
else:
self.props.style.backgroundColor = "green"
Thank you so much, It worked.