Lightswitch load all data or run a async method synchronously

217 views Asked by At

I have a grid with data in Lighswitch application. Grid has on every column posibility to filter column. Thanks to lsEnhancedTable

Right now I am sending an ajax request to the web api controler with the list of ids of the Customers that I want to export. It works but with a lot of data it is very slow because I have to turn off the paging of the data to get all visible customers ids so I can iterate over the VisualCollection.

To optimize this I would have to turn on back the paging of the data to 50 records so that the initial load is fast and move the loading of the data to a save/export to excel button.

Possible solutions:

  • Load data all data on save button click. To do this I have to somehow load all items before I can iterate over collection.

The code bellow locks UI thread since the loadMore is async. How to load all data synchronously? Ideally I would like to have some kind of progress view using a msls.showProgress.

while(3<4)
    {
        if (screen.tblCustomers.canLoadMore) {
            screen.tblCustomers.loadMore();
        }
        else
            break;
    }

var visibleItemsIds = msls.iterate(screen.tblCustomers.data)
                       .where(function (c) {
                           return c;
                       })
  • Second approach would be turn on paging and pass just the filters applied by the users to the web api controller so I can query database and return only filtered records. But I don't know how to do that.

  • Third approach is the one that I am using right now. Turn off the paging->iterate over visual collection, get the customers id, pass them to the controller and return a filtered excel. This doesn't work well when there are a lot of records.

  • Iterate over filtered collection in the server side? I don't know if there is a way to do this in Lighswitch?

1

There are 1 answers

0
Kris On

Here's an option for client side javascript.

// First build the OData filter string.

var filter = "(FieldName eq " + msls._toODataString("value", ":String") + ")";

// Then query the database.

myapp.activeDataWorkspace.ApplicationData.[TableName].filter(filter).execute().then(function (result) { ... });