cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
haqian
Frequent Visitor

Powerapp Table

Hello! So I am creating a test management app, and one of the features required of my app is that it must display a table of user inputed information. Is there a way to generate the size of the table based on user input? For example, I ask the user how many steps they need and if they enter "20", a table with 20 rows will generate. Thank you! 

1 ACCEPTED SOLUTION

Accepted Solutions

No worries!

The first thing to figure out is when should the Collection be created. It sounded like you wanted some sort of User input to dictate how many rows the table should include. Therefore, we can use a TextInput control to capture the number of rows and then create a collection to show those rows.

 

  1. Add a TextInput control (for this example, it'll be called TextInput1)
  2. If you want the table to generate after the set the TextInput1 value
    • Set the Format property of TextInput1 to TextFormat.Number
    • Set the DelayOuput property of TextInput1 to true
    • Set the OnChange property of TextInput1 to include this function

 

With(
    {rowsToCreate: Sequence (Value (Self.Text))},
    ForAll (
        rowsToCreate,
        Collect (
            colTable,
            {
                column1: "Value1",
                column2: "Value2"
            }
        )
    )
) 

 

  1. Add a Gallery control (or Data Table)
    • Set the Item property to colTable
  2. Map column1 and column2 to controls/columns, to show their values
  3. Enter value(s) into TextInput1 and see the Gallery/Data Table update as needed

 

This should hopefully address the concepts. Then you can expand upon them to only create the collection once, or with a different mechanism for determining the number of rows. Then you can also add more columns to the table/collection, and find ways to set those as something other than just plain text. Enjoy!

View solution in original post

5 REPLIES 5
GarethPrisk
Resident Rockstar
Resident Rockstar

Yes, this possible.

The Sequence function, coupled with ForAll is a great way to accomplish this. The Sequence function will allow you to generate a table of rows for X number, up to 50k. You can have this be a user input, to let them set a value.

 

Then you can write a function like this:

 

With( { rowsToCreate: Sequence ( Value ( TextInput.Value ) ) } , ForAll ( rowsToCreate, Collect ( colTable , { column1: "Value1", column2: "Value2" } ) ) )

@GarethPrisk 

I love the SEQUENCE function and your idea:

With( { rowsToCreate: Sequence ( Value ( TextInput.Value ) ) } , ForAll ( rowsToCreate, Collect ( colTable , { column1: "Value1", column2: "Value2" } ) ) )

 

I wanted to share a slightly more concise way of writing it without the WITH function.

ClearCollect(colTable, ForAll(Sequence(Value(TextInput.Value)), { column1: "Value1", column2: "Value2" }))

 

Any credit for the solution should go to you.  Just wanted to share my finding because I’m totally nerding out over SEQUENCE!

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up." 

That's a really interesting pattern!

I have always put collects inside my ForAlls, but never thought to collect the ForAll itself.

It would be interesting to test this with the monitor to see how it handles the API calls and the performance of each approach.

Cheers!

haqian
Frequent Visitor

@mdevaney  @GarethPrisk 

I'm sorry, I'm new to powerapps and am still trying to figure out all the functions. I created a new empty gallery and tried putting your code into "items", but I keep getting errors in the code and can't seem to fix it. Any ideas? 

No worries!

The first thing to figure out is when should the Collection be created. It sounded like you wanted some sort of User input to dictate how many rows the table should include. Therefore, we can use a TextInput control to capture the number of rows and then create a collection to show those rows.

 

  1. Add a TextInput control (for this example, it'll be called TextInput1)
  2. If you want the table to generate after the set the TextInput1 value
    • Set the Format property of TextInput1 to TextFormat.Number
    • Set the DelayOuput property of TextInput1 to true
    • Set the OnChange property of TextInput1 to include this function

 

With(
    {rowsToCreate: Sequence (Value (Self.Text))},
    ForAll (
        rowsToCreate,
        Collect (
            colTable,
            {
                column1: "Value1",
                column2: "Value2"
            }
        )
    )
) 

 

  1. Add a Gallery control (or Data Table)
    • Set the Item property to colTable
  2. Map column1 and column2 to controls/columns, to show their values
  3. Enter value(s) into TextInput1 and see the Gallery/Data Table update as needed

 

This should hopefully address the concepts. Then you can expand upon them to only create the collection once, or with a different mechanism for determining the number of rows. Then you can also add more columns to the table/collection, and find ways to set those as something other than just plain text. Enjoy!

View solution in original post

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,781)