How to create a todatasubset with Column values have array of elements?

Certified Senior Developer

Hi,

We have array of elements as Column data. with those we need to create todatasubset.

Example like I have 4 Array of elements like each

CustomerName Array,

ProductName Array,

Qty Array,

Price Array.

 

Please let me know how to create with these elements into data subset to use it in paging grid.

Thanks in advance.

  Discussion posts and replies are publicly visible

  • load(
    local!custArray:{"aaa","bbb","ccc"},
    local!prodNmArray:{"ddd","eee","ggg"},
    local!qtyArray:{10,20,30},
    local!priceArray:{40,50,60},
    local!array:merge(local!custArray,local!prodNmArray,local!qtyArray,local!priceArray),
    todatasubset(local!array,topaginginfo(1,-1))
    )

    If i am not wrong, this is what you are expecting.
  • 0
    Certified Senior Developer
    in reply to megharanib
    Hi,
    More or less I am expecting the same. but when I am trying to render to paging grid its not happening. todatasubset(local!array,topaginginfo(1,-1)).totalCount resulting only one row.

    we need to render this todatasubsset into paging grid. help me how to achieve this.

    Thanks for prompt response.
  • Hi megharanib,

    I tried with the same code and it is working in my case. I think the data what you created is of type "List of Variant". Convert into dictionary before forming the datasubset using cast(194, data). Then you will get the desired totalcount.

    I hope this will work
  • 0
    Certified Senior Developer
    in reply to krishnaprasadd
    Can you provide the working sample please
  • Hi megharanib,

    I tried with the same Example and it is working for me without using the cast function. If you Still facing the issue just provide some sample data to me so that it will be helpful for me to find out the issue.

    Please find the Sample Code below:

    load(
    local!custArray: {
    "aaa",
    "bbb",
    "ccc"
    },
    local!prodNmArray: {
    "ddd",
    "eee",
    "ggg"
    },
    local!qtyArray: {
    10,
    20,
    30
    },
    local!priceArray: {
    40,
    50,
    60
    },
    local!array: apply(
    rule!POC_genericTestRule(
    customerName: _,
    productName: _,
    quantity: _,
    price: _
    ),
    merge(
    local!custArray,
    local!prodNmArray,
    local!qtyArray,
    local!priceArray
    )
    ),
    local!finalData: todatasubset(
    local!array,
    topaginginfo(
    1,
    - 1
    )
    ),
    a!formLayout(
    label: "Test Data",
    firstColumnContents: {
    a!gridField(
    label: "Test",
    totalCount: local!finalData.totalCount,
    columns: {
    a!gridTextColumn(
    label: "Customer",
    data: index(
    local!finalData.data,
    "customerName",
    ""
    )
    ),
    a!gridTextColumn(
    label: "Product Name",
    data: index(
    local!finalData.data,
    "productName",
    ""
    )
    ),
    a!gridTextColumn(
    label: "Quantity",
    data: index(
    local!finalData.data,
    "quantity",
    ""
    )
    ),
    a!gridTextColumn(
    label: "Price",
    data: index(
    local!finalData.data,
    "price",
    ""
    )
    )
    },
    value: a!pagingInfo(
    1,
    - 1
    )
    )
    }
    )
    )

    POC_genericTestRule:

    {
    customerName: ri!customerName,
    productName: ri!productName,
    quantity: ri!quantity,
    price: ri!price
    }
  • Adding some little changes:

    load(
      local!custArray: touniformstring( "aaa", "bbb", "ccc" ),
      local!prodNmArray: { "ddd", "eee", "ggg" },
      local!qtyArray: { 10, null, 30 },
      local!priceArray: { 40, 50, 60 },
      local!array: a!forEach(
        items: local!custArray,
        expression: {
          customerName: index(local!custArray, fv!index, null),
          productName: index(local!prodNmArray, fv!index, null),
          quantity: index(local!qtyArray, fv!index, null),
          price: index(local!priceArray, fv!index, null)
        }
      ),
      local!finalData: todatasubset(
        local!array,
        topaginginfo( 1, - 1 )
      ),
      a!formLayout(
        label: "Test Data",
        contents: {
          a!gridField(
            label: "Test",
            totalCount: local!finalData.totalCount,
            columns: {
              a!gridTextColumn(
                label: "Customer",
                data: index( local!finalData.data, "customerName", null )
              ),
              a!gridTextColumn(
                label: "Product Name",
                data: index( local!finalData.data, "productName", null )
              ),
              a!gridTextColumn(
                label: "Quantity",
                data: index( local!finalData.data, "quantity", null )
              ),
              a!gridTextColumn(
                label: "Price",
                data: index( local!finalData.data, "price", null )
              )
            },
            value: a!pagingInfo( 1, - 1 )
          )
        }
      )
    )

    Hope it solves your issue

  • 0
    Certified Senior Developer
    in reply to Brazil Vibanco

    Thanks for the working solution. here is the little updated version by enabling the selection to get the selected row indexes.

    load(
      local!custArray: touniformstring( "aaa", "bbb", "ccc" ),
      local!prodNmArray: { "ddd", "eee", "ggg" },
      local!qtyArray: { 10, null, 30 },
      local!priceArray: { 40, 50, 60 },
      local!array: a!forEach(
        items: local!custArray,
        expression: {
          customerName: index(local!custArray, fv!index, null),
          productName: index(local!prodNmArray, fv!index, null),
          quantity: index(local!qtyArray, fv!index, null),
          price: index(local!priceArray, fv!index, null)
        }
      ),
      local!gridSelection:a!gridSelection(
        pagingInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: 10
      )   
      ),
      local!finalData: todatasubset(
        local!array,
        topaginginfo( 1, - 1 )
      ),
      a!formLayout(
        label: "Test Data" & local!gridSelection.selected,
        contents: {
          a!gridField(
            label: "Test",
            totalCount: local!finalData.totalCount,
            columns: {
              a!gridTextColumn(
                label: "Customer",
                data: index( local!finalData.data, "customerName", null )
              ),
              a!gridTextColumn(
                label: "Product Name",
                data: index( local!finalData.data, "productName", null )
              ),
              a!gridTextColumn(
                label: "Quantity",
                data: index( local!finalData.data, "quantity", null )
              ),
              a!gridTextColumn(
                label: "Price",
                data: index( local!finalData.data, "price", null )
              )
            },
            value: local!gridSelection,
            saveInto: a!save(target:local!gridSelection,value:save!value),
            identifiers: local!finalData.identifiers,
            selection: true
          )
        }
      )
    )

     

    Thanks a lot. its solved my requirements