locked
HTML Client (Visual Studio 2013) - How to force a refresh of an entity's collection? RRS feed

  • Question

  • Hi LightSwitchers,

    I have a custom control in the form of a Kendo UI grid which displays data from two entities.  Let's say Orders and Documents.  The data context of the custom control is set to Orders.  In the custom control's render method I get the orders and the corresponding documents.  Within the grid there's a Kendo UI upload control for each order.  When a document has been uploaded successfully, I want to get the order's documents collection again with the aim of refreshing the grid's data so the new document is visible.  I've tried to do this using the following when the upload control's success event fires.

    contentItem.value.data.forEach(function (order) {
        order.getDocuments().then(function (documents) {
            // Update the grid with the fresh list of documents
        });
    });

    I was expecting this to trigger an HTTP request for the data but this doesn't happen.  All that's returned is the original data.  I've also tried this using the new .refresh() method but with the same results.

    contentItem.value.refresh().then(function () {
        contentItem.value.data.forEach(function (order) {
            order.getDocuments().then(function (documents) {
                // Update the grid with the fresh list of documents
            });
        });
    });

    All this code sits in the custom control's render method.  Is there any way to force an update in this scenario?

    Monday, October 28, 2013 12:21 PM

Answers

  • It sounds like you need Documents to be eager loaded instead of lazy loaded by default.

    Two possible solutions:

    1. Explicitly include in your custom control's View the corresponding Order and Document entities.  This will trigger LS to eager load it.

    2. Use LS query syntax with .expand()

    myapp.activeDataWorkspace.ApplicationData.Orders.expand("Documents")

    .then(function(results) {

    // pass results.results to Kendo UI grid

    });


    • Marked as answer by T-Brutz Thursday, October 31, 2013 4:50 AM
    Tuesday, October 29, 2013 1:00 AM

All replies

  • It sounds like you need Documents to be eager loaded instead of lazy loaded by default.

    Two possible solutions:

    1. Explicitly include in your custom control's View the corresponding Order and Document entities.  This will trigger LS to eager load it.

    2. Use LS query syntax with .expand()

    myapp.activeDataWorkspace.ApplicationData.Orders.expand("Documents")

    .then(function(results) {

    // pass results.results to Kendo UI grid

    });


    • Marked as answer by T-Brutz Thursday, October 31, 2013 4:50 AM
    Tuesday, October 29, 2013 1:00 AM
  • Thanks Allen, you put me on the right track.  I used the LS query syntax but rather than use .expand() to eager load the documents for all orders, I used the following to get the documents for the corresponding order.

    myapp.activeDataWorkspace.ApplicationData.Documents.filter('Document_Order eq ' + order.id).execute().then(function (documents) {
        // Update the grid
    });
    Thanks for your help!


    Thursday, October 31, 2013 4:50 AM