Adam Bergeron
Adam Bergeron

Reputation: 525

Table Not Updating After Adding Entry

Short version: New entries don't appear in a table with a Query Builder filter unless I manually refresh the page.


Long Version: I have a Table that is using a Datasource Query Builder to filter out entries that have been marked as Complete and Delivered.

So the model is SystemOrders, but the datasource for the table is the one with the filters added (SystemOrders_HideComplete). All of this works fine.

When users create a new entry for the database they click an "Add" button which opens a Page Fragment. They can enter all of their data and it gets written, but the table doesn't automatically refresh when the Fragment closes and it does not show the new entry.

Refreshing the browser page or reloading the datasource with a custom button on the same page as the table (listed below) causes the new entry to show up.

widget.datasource.query.clearFilters();
var datasource = app.datasources.SystemOrders_HideComplete;
datasource.load();

I tried adjusting the Submit button for the Page Fragment with the hopes that it would save users from having to manually refresh the page, but that doesn't seem to work either:

widget.datasource.createItem();
var datasource = app.datasources.SystemOrders_HideComplete;
datasource.load();
app.closeDialog();

I assuming this is maybe because the datasource.load(); command is coming from a Fragment?

Any help in figuring out a way to have the new entries appear automatically would be greatly appreciated.

Upvotes: 2

Views: 654

Answers (1)

Pavel Shkleinik
Pavel Shkleinik

Reputation: 6347

In theory, if you use the same datasource for your table and create page fragment then new item should append autamatically:

// Table datasource
app.datasources.SystemOrders_HideComplete

// Page fragment datasource
app.datasources.SystemOrders_HideComplete.modes.create

If by some reason you want to use different datasource to create new items, you can either push new record to the list datasource(in this case you will avoid extra call to server and provide 100% guarntee that new item will appear in the list, even if it doesn't fit to selected filters/paging/sorting...):

widget.datasource.createItem({
  success: function(record) {
    app.datasources.SystemOrders_HideComplete.items.push(record);
    app.closeDialog();
  },
  failure: function(error) {
    // TODO: handle error
  }
});

... or force list datasource to reload (in this case you'll get fresh data that fits your filters, but may be it'll miss your new item):

widget.datasource.createItem({
  success: function(record) {
    app.datasources.SystemOrders_HideComplete.load();
    app.closeDialog();
  },
  failure: function(error) {
    // TODO: handle error
  }
});

Upvotes: 2

Related Questions