HELP! How can I refresh data in a list-view without refreshing the page?

3
Hi I’m new to Mendix and the concept of low level programming. I’m a University student studying Computer Science in my first year and familiar with languages such as: JavaScript, C#, Python, HTML and CSS. I’ve created an app to display weather conditions which is called via a REST API in a Microflow. The problem I’m facing is the app only seems to request the data once (when the page loads) and I want the data to update whenever I click the: “refresh” button.  So far, I’ve tried creating an action button to call the same Microflow - I’ve checked the Chrome network tab and can see the new values – however my JSON object doesn’t appear to update inside my ListView. Please can someone help me with this as I’ve spent countless hours scratching my head trying to figure this one out :) Kind regards, Gareth Davies
asked
5 answers
4

As addition, if you use a template grid instead of listview, you can set an auto refresh and your page will refresh itself in a given time interval.

answered
2

Hi Gareth,

Two things you could do: 

  1. Use the Microflow Timer widget in the App Store to update on an interval. Place the widget in the list view and this will auto-update
  2. OR place the refresh button in the List View contents and have the button call a microflow that only refreshes the object in context (the rest of the list view will remain static)

Either of those solutions will work, but #2 might be your best bet. The button within the contents of a List View allows you to isolate that specific object. 

answered
2

In addition to the above answers, your application and, although relevant, not a solution to your problem. May I suggest the following.

I see that each block uses the same datasource microflow. If you connect the JsonObject to a parent entity, I.e. ‘JsonObjectViewhelper’ with a 1-1 association, assuming its the same object each time, you can reduce the number of microflows triggered from 3 down to a single one. Create a dataview that uses the GetData microflow and output the viewhelper object. In this datasource microflow you create the viewhelper object, as well as do the GET request, followed by associating the jsonobject to the viewhelper.  Now, instead of a microflow for each block, simply use the dataview and retrieve the object over association, instead. 
 

Additionally, if you refresh the viewhelper object, by any of the above solutions, the data that’s associated is automatically refreshed as well. If you put the refresh button inside the dataview of the viewhelper object, you can simply use a microflow that has a single activity; the change object (viewhelper) with no attributes changed, but only the ‘refresh object’ ticket. This way the parent object will refresh, causing all data to be refreshed as well.

Combine this microflow withheld MicroflowTimer widget for automatic refreshes :)

Good luck!

answered
1

Gareth

It looks like your weather tiles are sourced by microflow.  If so, microflow sourced dataviews/listviews/datagrids only retrieve when the page is loaded.  To get the data to refresh, you can use the following approach:

  • create a single entity that has the attributes you want to display (temp, humidity, dust)
  • change the page with the tiles so that all of the tiles are inside of one dataview pointing to your new entity
  • change the microflow that calls the REST service as follows:
    • add a parameter pointing to your new entity
    • after calling the REST service, update the parameter with the values your rest service returns.  Make sure you set the Refresh in Client radio button to Yes in the microflow action that updates the entity
  • create a microflow to open the page with the tiles, this microflow should:
    • create a new object of the entity you just created
    • call the microflow the calls the REST service
    • opens the page, passing the object you just created an updated
  • on your page, you can create an action button that executes the REST call microflow.  This will update the values when you click the button
  • if you want the update to happen automatically, you can use the microflow timer widget from the appstore on your page to run the update microflow on a regular interval and update the values

Hope that helps,

Mike

answered
0

Hi. I know that this is a post a year ago, but may I know how did you make the box for Temperature, Humidity and Dust respectively please? What widget did you use?

answered