locked
Create Dynamic TextBox in LIghtSwitch RRS feed

  • Question

  • Hi Team,

    i am developing HTML client LightSwitch Application

    My doubt is i need to create textboxes in the screen which will not be bound to any entity. I want to display the aggregate value from the screen. 

    Department Name - Filter      

    Actual Effort Sum - TexField - 25 

    Planned Effort Sum - TexField - 30     

    Effort Variance - TexField - 5

    Resource Name

    Department

    Actual Effort

    Planned Effort

    Srikanth

    ABC

    10

    15

    Ashok

    ABC

    15

    15


    as shown in the above screen model (Since i cannot able to upload my browse screen snapshot)which is screen for the entity ResourceEfforts and i have one filter (Department Name) which is not optional, so when use enters the department it will display all the resource names with their efforts in the browse screen (from the ResourceEfforts entity) those who are comes under that particular department. 

    My Requirement is, i want to show the aggregate value from the screen values (sum of Actual Effort, sum of Planned Effort and total Effort variance) in the dynamic text fields for the entered department value in the filter. 

    i have been thinking of using Linq Query to evaluate the value but i need to pass the entered department filter value in the 'where' condition of the linq query.  

    so anyone please tell me if you have suggestions for this scenario, it will be really helpful.

    Thanks,

    Srikanth Anantharaman


    Wednesday, March 25, 2015 12:02 PM

Answers

  • Hello Srikanth,

    You may find the following link helpful: http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/1207/HUY-Volume-III-ndash-Popups-Dirty-Visual-Collections-and-Using-Prototypes-To-Calculate-Child-Collections.aspx

    Scroll down the page until you see a section called Using Prototypes To Calculate Child Records.

    Another way is to bind your Filter property to the parameter of the dataset on that screen.  Click on Edit Query on the right hand side of the Table name, then add a new filter at the top saying something like  Where Department equals , then pick Parameter from the third dropdown and Add new from the final dropdown.

    This will create a new Parameter at the bottom of the query screen called "Department" (although you can rename it by clicking on its name, if you like.)   If you want to see all Departments if a specific one is not entered, check the box marked "Is Optional".

    Click the link to go back to your screen in the upper left.  Select your table again, and now you'll see a new section at the bottom called Query Parameters, and your new parameter should be there. Click on your new parameter, and in the Properties window, set the Parameter Binding to the name of the screen property you created, DepartmentName, or whatever its name is.  Test your program by hitting F5 or clicking Start, and you should see that the table does change whenever you type something into your Department Name - Filter box.

    Once that works, the next thing to do is go to the PostRender event for your DepartmentName box and add a contentItem.dataBind so that you can calculate the display fields immediately when someone puts a department into the box.  Something like:

    myapp.DepartmentScreen.DepartmentName.PostRender(element,contentItem) {

       contentItem.dataBind("value",function(newValue) {

          if(newValue != undefined && newValue != null) {

             contentItem.screen.getDepartmentTableItems().then(function() {

                var actualSum = 0;

                var plannedSum = 0;

                contentItem.screen.DepartmentTableItems.foreach(function(item) {

                   actualSum += item.ActualEffort;

                   plannedEffortSum += item.PlannedEffort;

                });

                screen.ActualEffortSum = actualSum;

                screen.PlannedEffortSum = plannedSum;

                screen.EffortVariance = plannedSum - actualSum;

             });

          }

       });

    }

    • Marked as answer by Angie Xu Tuesday, April 7, 2015 8:44 AM
    Monday, March 30, 2015 8:51 PM

All replies

  • So my requirement is, dynamic text fields i need to create and display the total planned effort and actual effort and its effort variance for that particular department displaying on the screen.

    Do you mean that bind different query parameters to one TextBox? Similar reference: https://social.msdn.microsoft.com/Forums/en-US/c770f9e5-a08e-454a-a7f1-30d38f8ab1af/binding-different-query-parameters-to-one-textbox-html-client?forum=lightswitch 

    Thursday, March 26, 2015 6:21 AM
  • Sorry for the not so clear requirement from my side, i want to show the aggregate value from the screen values (Actual Effort and Planned Effort) in the text fields based on the entered value in the filter. 

    thanks for your reply but the link you have given is related to different query parameter for the single filter. 


    Srikanth Anantharaman

    Thursday, March 26, 2015 6:25 AM
  • Hello Srikanth,

    You may find the following link helpful: http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/1207/HUY-Volume-III-ndash-Popups-Dirty-Visual-Collections-and-Using-Prototypes-To-Calculate-Child-Collections.aspx

    Scroll down the page until you see a section called Using Prototypes To Calculate Child Records.

    Another way is to bind your Filter property to the parameter of the dataset on that screen.  Click on Edit Query on the right hand side of the Table name, then add a new filter at the top saying something like  Where Department equals , then pick Parameter from the third dropdown and Add new from the final dropdown.

    This will create a new Parameter at the bottom of the query screen called "Department" (although you can rename it by clicking on its name, if you like.)   If you want to see all Departments if a specific one is not entered, check the box marked "Is Optional".

    Click the link to go back to your screen in the upper left.  Select your table again, and now you'll see a new section at the bottom called Query Parameters, and your new parameter should be there. Click on your new parameter, and in the Properties window, set the Parameter Binding to the name of the screen property you created, DepartmentName, or whatever its name is.  Test your program by hitting F5 or clicking Start, and you should see that the table does change whenever you type something into your Department Name - Filter box.

    Once that works, the next thing to do is go to the PostRender event for your DepartmentName box and add a contentItem.dataBind so that you can calculate the display fields immediately when someone puts a department into the box.  Something like:

    myapp.DepartmentScreen.DepartmentName.PostRender(element,contentItem) {

       contentItem.dataBind("value",function(newValue) {

          if(newValue != undefined && newValue != null) {

             contentItem.screen.getDepartmentTableItems().then(function() {

                var actualSum = 0;

                var plannedSum = 0;

                contentItem.screen.DepartmentTableItems.foreach(function(item) {

                   actualSum += item.ActualEffort;

                   plannedEffortSum += item.PlannedEffort;

                });

                screen.ActualEffortSum = actualSum;

                screen.PlannedEffortSum = plannedSum;

                screen.EffortVariance = plannedSum - actualSum;

             });

          }

       });

    }

    • Marked as answer by Angie Xu Tuesday, April 7, 2015 8:44 AM
    Monday, March 30, 2015 8:51 PM