Skip to main content
kavyam0002
September 13, 2022
Solved

add grid automatically

  • September 13, 2022
  • 9 replies
  • 0 views

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 

    Best answer by ujjwalr0002

    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
    September 13, 2022

    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
    September 13, 2022

    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
    September 13, 2022

    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
    September 14, 2022

    can you please give snippet of it that would be helpful 

    puneets0004
    September 14, 2022
    Participating Frequently
    September 14, 2022

    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
    September 21, 2022

    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
    September 21, 2022

    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?