locked
HTML CLIENT: How Can I Scroll a Table until The SelectedItem? RRS feed

  • Question

  • Hi there!

    To select an item in a table I use the following code: screen.Products.selectedItem = referenceProduct.Product;

    But, how to scroll the table until the SelectedItem ? I want, after select an item via code, make its row visible and selected.

    Best regards,


    Ciro

    Tuesday, November 25, 2014 8:38 PM

Answers

  • This may help:

    Understanding The LightSwitch HTML Client Visual Collection

    Basically you can keep calling the .get and loadMore() methods until the record you want is loaded:

    myapp.BrowseCustomers.CallGetCustomers_execute = function (screen) {
        // Call getCustomers
        screen.getCustomers().then(function (result) {
            var index = result.data.length; // gets length of the full Customer array
            // The last Customer found in the 
            // collection will be 
            // set to LatestLoadedCustomer
            screen.LatestLoadedCustomer = result.data[index - 1]; // compensate for 0-based index
    
            // Show the Popup to display 
            // LatestLoadedCustomer
            screen.showPopup("LatestCustomer");
        });
    };

    myapp.BrowseCustomers.GetMoreRecords_execute = function (screen) {
        if (screen.Customers.canLoadMore) {
            // We can load more records -- load them
            screen.Customers.loadMore().then(function (result) {
                var index = result.items.length; // gets length of the full Customer array
                // The last Customer found in the 
                // collection will be 
                // set to LatestLoadedCustomer
                screen.LatestLoadedCustomer = result.items[index - 1]; // compensate for 0-based index
    
                // Show the Popup to display 
                // LatestLoadedCustomer
                screen.showPopup("LatestCustomer");
    
                // Update the total records display
                DisplayCustomerCount(screen);
            });
        }
    };


    Unleash the Power - Get the LightSwitch 2013 HTML Client / SharePoint 2013 book

    http://LightSwitchHelpWebsite.com





    • Edited by ADefwebserver Tuesday, December 2, 2014 6:18 PM
    • Marked as answer by Oric.CQ Tuesday, December 2, 2014 8:47 PM
    Tuesday, December 2, 2014 6:13 PM

All replies

  • Any suggestion, please?

    Best regards,


    Ciro

    Monday, December 1, 2014 8:48 PM
  • Hi,

    Do you navigate to another screen first and where do you use the code?

    Created, execute via button or where?

    Sven


    Sven Elm

    Tuesday, December 2, 2014 7:55 AM
  • Hi, Sven! Thanks to reply!

    I need answer for both situation: CREATED and EXECUTE VIA BUTTON.

    Best regards,


    Ciro

    Tuesday, December 2, 2014 5:10 PM
  • This may help:

    Understanding The LightSwitch HTML Client Visual Collection

    Basically you can keep calling the .get and loadMore() methods until the record you want is loaded:

    myapp.BrowseCustomers.CallGetCustomers_execute = function (screen) {
        // Call getCustomers
        screen.getCustomers().then(function (result) {
            var index = result.data.length; // gets length of the full Customer array
            // The last Customer found in the 
            // collection will be 
            // set to LatestLoadedCustomer
            screen.LatestLoadedCustomer = result.data[index - 1]; // compensate for 0-based index
    
            // Show the Popup to display 
            // LatestLoadedCustomer
            screen.showPopup("LatestCustomer");
        });
    };

    myapp.BrowseCustomers.GetMoreRecords_execute = function (screen) {
        if (screen.Customers.canLoadMore) {
            // We can load more records -- load them
            screen.Customers.loadMore().then(function (result) {
                var index = result.items.length; // gets length of the full Customer array
                // The last Customer found in the 
                // collection will be 
                // set to LatestLoadedCustomer
                screen.LatestLoadedCustomer = result.items[index - 1]; // compensate for 0-based index
    
                // Show the Popup to display 
                // LatestLoadedCustomer
                screen.showPopup("LatestCustomer");
    
                // Update the total records display
                DisplayCustomerCount(screen);
            });
        }
    };


    Unleash the Power - Get the LightSwitch 2013 HTML Client / SharePoint 2013 book

    http://LightSwitchHelpWebsite.com





    • Edited by ADefwebserver Tuesday, December 2, 2014 6:18 PM
    • Marked as answer by Oric.CQ Tuesday, December 2, 2014 8:47 PM
    Tuesday, December 2, 2014 6:13 PM
  • Hi master Michael! Thank you to reply!

    Your answer inspired me another question.

    Now, it's easy to scroll the screen until the selected item. But, for example, how can I select the first custmer's name whose first name is Michael?

    Best regards


    Ciro

    Tuesday, December 2, 2014 8:26 PM
  • How can I select the first custmer's name whose first name is Michael?


    In any list that you display where you allow the user to click on an element in that list, the element selected will be set as the .selectedItem in that list (like ("screen.Customers.selectedItem"). To set this, I usually make a popup that allows a person to search for a Customer, and then select a Customer. I would not try to loop though the list for them and try to select it for them because their web browser is doing a lot of hard work and will probably lock up in a lot of cases.

    Unleash the Power - Get the LightSwitch 2013 HTML Client / SharePoint 2013 book

    http://LightSwitchHelpWebsite.com

    Tuesday, December 2, 2014 8:36 PM
  • Thank you, Michael!

    Best regards,


    Ciro

    Tuesday, December 2, 2014 8:47 PM