There are two different ways to refresh the UI from plugins, depending on the plugin type you are developing.
The way to refresh in IContentPluginBase is the same as IPluginBase.
Refreshing with IPluginBase
IPluginBase plugins have the following EventHandler:
public event EventHandler OnExecute;
The following code snippet can be called from the method Execute(...)
to refresh the UI of the Grid Page.
PluginEventArgs arg = new PluginEventArgs(); arg.EventType = PluginEvent.RefreshGrid; OnExecute(null, arg);
To exemplify this, here is an example plugin that can be used to double the amount of OrderLines on an Order.
/* * Creates dummy data by doubling the amount of DebtorOrderLines */ public ErrorCodes Execute(UnicontaBaseEntity master, UnicontaBaseEntity currentRow, IEnumerable<UnicontaBaseEntity> source, string command, string args) { // Cast source to its run time type. var allLines = (IEnumerable<DebtorOrderLineClient>) source; var newLines = new List<DebtorOrderLineClient>(); // Loop over all lines and Insert an extra line. foreach (var line in allLines) { var newLine = new DebtorOrderLineClient { Item = line.Item, Price = line.Price, Text = line.Text, Date = DateTime.Now, }; newLines.Add(newLine); newLine.SetMaster(master); } // Insert new order lines. var result = Crud.Insert(newLines).Result; // Call refresh code to update UI automatically. PluginEventArgs arg = new PluginEventArgs(); arg.EventType = PluginEvent.RefreshGrid; OnExecute(null, arg); return result; }
Refreshing with PageEventsBase
You can take theRefreshGrid()
method and paste into your own code base. Now you can just call RefreshGrid when you want to refresh the UI.
Note that this will call some events of the PageEventsBase. For instance, if this method is called from RecrodPropertyChanged, it results in an infinite loop.
private void RefreshGrid() { var methodInfo = this.page.GetType().GetMethod("Filter", new Type[] { }); if (methodInfo != null) methodInfo.Invoke(this.page, null); }