I have a requirement to list events via view, but these events are categorized as past, ongoing and upcoming events. View results should show ongoing first, then upcoming and past events in the same view. I have used a computed(integer) field to set the value for each category. While creating a node based on start/end date I am setting this field value to 1(ongoing),2(upcoming), and 3(past). In the views, I am sorting the events based on this numeric field Ascending. It works fine, but issues arise when upcoming events become ongoing, then this computed field value is not updated to show as ongoing. How do I update this field value before this view is rendered?
You cannot (or at least, really should not) force nodes to be re-saved before accessing a view. Such an approach is very inefficient.
The issue here is that you have a computed field that does a calculation based on a date and the current time. If the date is in the future, the field has one value, and if the date is in the past, the field has another value. Using a computed field here is not a good approach because as time passes, you have to re-save the nodes to ensure they have correct values.
One (inefficient) way to update the computed fields would be to batch re-save your nodes in cron.
A similar approach would be to use the Job Scheduler module to set up jobs to periodically resave the nodes.
However, I don't think saving a computed value is the right approach if it may have to be recomputed when a user accesses a node or a view. If you need to compute a value on the fly, then don't store it in a computed field.
Instead, do the computing when you process the view. To do this, you can write a custom Views sort plugin. You can move the computed field logic to this plugin and then sort based on the date field (instead of the computed field).