Skip to main content
kavyam0002
Brainy
Sep 13, 2022 12:41 PM UTC
Solved

add grid automatically

Hi 

my requirements is i have 2 grids one after the other when i add a row in the first grid i have to get one row automatically in the 2nd grid [second grid will be user input grid]

can anyone help me on this 

    Participating Frequently
    Sep 21, 2022 10:02 AM UTC

    Check this out..

    = a!localVariables(
      local!items: { { item: null, qty: null, unitPrice: null },  },
      local!item2: { { item_grid: null, item_qty: null } },
      {
        a!gridLayout(
          label: "Products1",
          instructions: "Update the item name, quantity, or unit price.",
          headerCells: {
            a!gridLayoutHeaderCell(label: "Item"),
            a!gridLayoutHeaderCell(label: "Qty"),
            a!gridLayoutHeaderCell(label: "Unit Price"),
            
          },
          rows: a!forEach(
            items: local!items,
            expression: {
              a!gridRowLayout(
                contents: {
                  a!textField(
                    value: fv!item.item,
                    saveInto: fv!item.item
                  ),
                  a!integerField(value: fv!item.qty, saveInto: fv!item.qty),
                  a!floatingPointField(
                    value: fv!item.unitPrice,
                    saveInto: fv!item.unitPrice
                  ),
                  
                }
              )
            }
          ),
          rowHeader: 1,
          addRowLink: a!dynamicLink(
            label: "Add new row",
            saveInto: {
              a!save(
                local!items,
                append(
                  local!items,
                  { item: null, qty: null, unitPrice: null }
                )
              ),
              a!save(
                local!item2,
                append(
                  local!item2,
                  { item_grid: null, item_qty: null }
                )
              )
            }
          )
        ),
        a!gridLayout(
          label: "Products2",
          instructions: "Update the item name, quantity, or unit price.",
          headerCells: {
            a!gridLayoutHeaderCell(label: "Item"),
            a!gridLayoutHeaderCell(label: "Qty"),
            
          },
          rows: a!forEach(
            items: local!item2,
            expression: {
              a!gridRowLayout(
                contents: {
                  a!textField(
                    value: fv!item.item_grid,
                    saveInto: fv!item.item_grid
                  ),
                  a!integerField(
                    value: fv!item.item_qty,
                    saveInto: fv!item.item_qty
                  ),
                  
                }
              )
            }
          ),
          rowHeader: 1,
          addRowLink: a!dynamicLink(
            label: "Add new row",
            saveInto: {
              a!save(
                local!item2,
                append(
                  local!item2,
                  { item_grid: null, item_qty: null }
                )
              ),
              a!save(
                local!items,
                append(
                  local!items,
                  { item: null, qty: null, unitPrice: null }
                )
              )
            }
          )
        )
      }
    )

    9 replies

    durgeshk0003
    Participating Frequently
    Sep 13, 2022 12:56 PM UTC

    I hope you are storing the data in local variable, in this case, set the refreshAfter attribute on a local variable which is used to populate the second grid. 

    mikes0011
    Brainy
    Sep 13, 2022 1:14 PM UTC

    This depends to a great extent on details you haven't provided here - your data structure, the nature of the relationship between corresponding rows on both grids, etc.

    In general I can offer this: the "add row" link in an editable grid can do basically anything you want, as a DynamicLink.  That includes the ability to add new/blank rows to two separate arrays at the same time, just as a more concrete hint.  That's true regardless of whether the arrays are stored in local variables, or in Rule Inputs (or a mixture of both).

    The Expression Guru
    Inspiring
    Sep 13, 2022 3:40 PM UTC

    While adding the row in the first grid from the dynamic link. on click, append 1 row to the second grid variable as well.

    kavyam0002
    Brainy
    Sep 14, 2022 4:50 AM UTC

    can you please give snippet of it that would be helpful 

    puneets0004
    Participating Frequently
    Sep 14, 2022 6:12 AM UTC
    Participating Frequently
    Sep 14, 2022 5:46 AM UTC

    Hi, 

    While using the editable grids we have a parameter as addRowLink there you can append new values to both the items which you are using for the grids.

    kavyam0002
    Brainy
    Sep 21, 2022 9:02 AM UTC

    Hi Ujjwal,

    can you help me with the sample code so that it will  be helpful for me. i have tried but not getting 

    stefanhelzle0001
    Brainy
    Sep 21, 2022 9:53 AM UTC

    Try to ignore the grids and concentrate on manipulating the underlying data stored in rule inputs or locals.

    Please try to explain what you tried and what failed. Do you have some code snippets you can share?