Editable Grid - Paging controlling number of records displayed per page

Certified Senior Developer

Hi All,

Is it possible to limit the number of rows displayed by an editable grid? I currently implemented paging but I doesn't do anything to the actual grid it keeps showing all the records. Basically I would like to do like a read only grid - show only 5 records then next page the 5 next following records like that. Is this possible?

thanks again

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    hi   yes you can implement pagination to editable grid, If your  data is modified what you can do is show initially all the rows as read only have edit in your grid column when you click enable specific row that will allow data for modification, if it is read only data you can go for read only grid 

  • 0
    Certified Senior Developer
    in reply to Abhishek Karumuru

    thanks ! could you advise how to do this? maybe if you can give me an example with this editable grid code:

    a!localVariables(
      local!items: {
        {item: "Item 1", qty: 1, unitPrice: 10},
        {item: "Item 2", qty: 2, unitPrice: 20},
        {item: "Item 3", qty: 3, unitPrice: 30},
        {item: "Item 4", qty: 4, unitPrice: 40},
        {item: "Item 5", qty: 5, unitPrice: 50},
        {item: "Item 6", qty: 6, unitPrice: 60},
        {item: "Item 7", qty: 7, unitPrice: 70},
        {item: "Item 8", qty: 8, unitPrice: 80},
        {item: "Item 9", qty: 9, unitPrice: 90},
        {item: "Item 10", qty: 10, unitPrice: 100}
      },
      a!gridLayout(
        label: "Products",
        instructions: "Update the item name, quantity, or unit price.",
        headerCells: {
          a!gridLayoutHeaderCell(label: "Item"),
          a!gridLayoutHeaderCell(label: "Qty"),
          a!gridLayoutHeaderCell(label: "Unit Price"),
          a!gridLayoutHeaderCell(label: "Total", align: "RIGHT")
        },
        columnConfigs: {
          a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 5),
          a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
          a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
          a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2)
        },
        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
              ),
              a!textField(
                value: dollar(tointeger(fv!item.qty) * todecimal(fv!item.unitPrice)),
                readOnly: true,
                align: "RIGHT"
              )
            }
          )  
        ),
        height: "SHORT",
        rowHeader: 1
      )
    )

  • 0
    Certified Senior Developer
    in reply to Maria

    Could you try this code 

    a!localVariables(
      local!items: {
        {item: "Item 1", qty: 1, unitPrice: 10},
        {item: "Item 2", qty: 2, unitPrice: 20},
        {item: "Item 3", qty: 3, unitPrice: 30},
        {item: "Item 4", qty: 4, unitPrice: 40},
        {item: "Item 5", qty: 5, unitPrice: 50},
        {item: "Item 6", qty: 6, unitPrice: 60},
        {item: "Item 7", qty: 7, unitPrice: 70},
        {item: "Item 8", qty: 8, unitPrice: 80},
        {item: "Item 9", qty: 9, unitPrice: 90},
        {item: "Item 10", qty: 10, unitPrice: 100}
      },
      local!pagingInfo: a!refreshVariable(
        value: a!pagingInfo(
          startIndex: 1,
          batchSize: 5,
          sort: a!sortInfo(field: "item", ascending: false())
        )),
        local!dataSubset:todatasubset(local!items,local!pagingInfo),
      
    
     { a!gridLayout(
        label: "Products",
        instructions: "Update the item name, quantity, or unit price.",
        headerCells: {
          a!gridLayoutHeaderCell(label: "Item"),
          a!gridLayoutHeaderCell(label: "Qty"),
          a!gridLayoutHeaderCell(label: "Unit Price"),
          a!gridLayoutHeaderCell(label: "Total", align: "RIGHT")
        },
        columnConfigs: {
          a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 5),
          a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
          a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
          a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2)
        },
        rows: a!forEach(
          items: local!dataSubset,
          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
              ),
              a!textField(
                value: dollar(tointeger(fv!item.qty) * todecimal(fv!item.unitPrice)),
                readOnly: true,
                align: "RIGHT"
              )
            }
          )  
        ),
        height: "SHORT",
        rowHeader: 1
      ),
      rule!customPaginationRule(
        pagingInfo: local!pagingInfo,
        totalCount: local!dataSubset.totalCount.
      )}
    )

  • 0
    Certified Senior Developer
    in reply to Abhishek Karumuru

    Create a interface rule for pagination and call in the code where i have called rule!CustomPaginationrule:

    a!sectionLayout(
      contents: {
        a!richTextDisplayField(
          align: "RIGHT",
          value: {
            a!richTextIcon(
              icon: "chevron-left",
              link: a!dynamicLink(
                saveInto: a!save(
                  ri!pagingInfo,
                  a!pagingInfo(
                    startIndex: ri!pagingInfo.startIndex - ri!pagingInfo.batchSize,
                    batchSize: ri!pagingInfo.batchSize,
                    sort: ri!pagingInfo.sort
                  )
                ),
                showWhen: ri!pagingInfo.startIndex > 1
              ),
              linkStyle: "STANDALONE"
            ),
            a!richTextItem(
              text: {
                char(32),
                a!richTextItem(
                  text: {
                    joinarray(
                      {
                        index(ri!pagingInfo, "startIndex", null),
                        char(45),
                        if(
                          (
                            index(ri!pagingInfo, "startIndex", null) + index(ri!pagingInfo, "batchSize", null) - 1
                          ) > ri!totalCount,
                          ri!totalCount,
                          (
                            index(ri!pagingInfo, "startIndex", null) + index(ri!pagingInfo, "batchSize", null) - 1
                          )
                        )
                      },
                      char(32)
                    )
                  },
                  style: "STRONG"
                ),
                char(32),
                joinarray({ "of", ri!totalCount }, char(32)),
                char(32)
              }
            ),
            a!richTextIcon(
              icon: "chevron-right",
              link: a!dynamicLink(
                saveInto: a!save(
                  ri!pagingInfo,
                  a!pagingInfo(
                    startIndex: ri!pagingInfo.startIndex + ri!pagingInfo.batchSize,
                    batchSize: ri!pagingInfo.batchSize,
                    sort: ri!pagingInfo.sort
                  )
                ),
                showWhen: ri!pagingInfo.startIndex < ri!totalCount - ri!pagingInfo.batchSize
              ),
              linkStyle: "STANDALONE"
            )
          }
        )
      }
    )

  • 0
    Certified Senior Developer
    in reply to Abhishek Karumuru

    I'm a bit confused I already have an interface rule for pagination like a showed in the picture- this is the code for it , what would be the main difference on how it works? to control like the actual number of records displayed?

      a!localVariables(
      a!sideBySideLayout(
         items: {
           a!sideBySideItem(
             item: a!richTextDisplayField(
               align: "RIGHT",
               value: {
                 /* Left Angle */
                 a!richTextIcon(
                   icon: "angle-double-left",
                   link: a!dynamicLink(
                     saveInto: {
                       a!save(ri!startIndex, 1),                  
                     },
                     showWhen: ri!startIndex <> 1
                   ),
                   linkStyle: "STANDALONE",
                   color: if(
                     ri!startIndex <> 1,
                     "STANDARD",
                     "SECONDARY"
                   )
                 ),
                 a!richTextIcon(
                   icon: "angle-left",
                   link: a!dynamicLink(
                     showWhen: ri!startIndex <> 1,
                     saveInto: a!save(
                       ri!startIndex,
                       ri!startIndex - ri!batchSize
                     )
                   ),
                   linkStyle: "STANDALONE",
                   color: if(
                     ri!startIndex <> 1,
                     "STANDARD",
                     "SECONDARY"
                   )
                 ),
                 /* Start Index */
                 a!richTextItem(
                   text: {
                     ri!startIndex, 
                     " - ",
                     if(
                       ri!startIndex + ri!batchSize - 1 > ri!totalCount,
                       ri!totalCount,
                       ri!startIndex + ri!batchSize - 1
                     )
                   },
                   style: "STRONG"
                 ),
                 /* Total Count */
                 a!richTextItem(
                   text: {
                     " of ", 
                     ri!totalCount
                   }
                 ),
                 /* Right Angle */
                 a!richTextIcon(
                   icon: "angle-right",
                   link: a!dynamicLink(
                     showWhen: (ri!startIndex + ri!batchSize - 1) < ri!totalCount,
                     label: "",
                     saveInto: a!save(
                       ri!startIndex,
                       ri!startIndex + ri!batchSize
                     )
                   ),
                   linkStyle: "STANDALONE",
                   color: if(                
                     ri!startIndex + ri!batchSize - 1 < ri!totalCount,                
                     "STANDARD",
                     "SECONDARY"
                   )           
                 ),
                 a!richTextIcon(
                   icon: "angle-double-right",
                   link: a!dynamicLink(
                     saveInto: {
                       a!save(
                         ri!startIndex, 
                         if(
                           mod(ri!totalCount, ri!batchSize) = 0,
                           ri!totalCount - ri!batchSize + 1,
                           ri!totalCount - mod(ri!totalCount, ri!batchSize) + 1
                         )
                       )
                     },
                     showWhen: ri!startIndex + ri!batchSize - 1 < ri!totalCount
                   ),
                   linkStyle: "STANDALONE",
                   color: if(                
                     ri!startIndex + ri!batchSize - 1 < ri!totalCount,                
                     "STANDARD",
                     "SECONDARY"
                   )
                 )
               }
             )
           )
         }
       )
       )

  • 0
    Certified Senior Developer
    in reply to Maria

    initially you need to convert your data into data subset and pass the pagination for data and custom pagination, based on the total count what you have given in custom pagination and based on batch size it will split the data into batches and display to you

  • 0
    Certified Senior Developer
    in reply to Abhishek Karumuru

    With this code it is still the same as I had before "it shows the paging" but it stills shows all the rows of data in grid 

  • 0
    Certified Senior Developer
    in reply to Maria

    Hi  could you please you try with codes which i given and check?

  • 0
    Certified Senior Developer
    in reply to Abhishek Karumuru

    Hi   Thats the one I tried, its the same.

Reply Children
  • 0
    Certified Senior Developer
    in reply to Maria

    Hi  I am not sure why it is not happening could you please share the latest update code so that we can identify 

  • 0
    Certified Senior Developer
    in reply to Abhishek Karumuru

    This is the code I have for the paging interface: 

    a!sectionLayout(
      contents: {
        a!richTextDisplayField(
          align: "RIGHT",
          value: {
            a!richTextIcon(
              icon: "chevron-left",
              link: a!dynamicLink(
                saveInto: a!save(
                  ri!pagingInfo,
                  a!pagingInfo(
                    startIndex: ri!pagingInfo.startIndex - ri!pagingInfo.batchSize,
                    batchSize: ri!pagingInfo.batchSize,
                    sort: ri!pagingInfo.sort
                  )
                ),
                showWhen: ri!pagingInfo.startIndex > 1
              ),
              linkStyle: "STANDALONE"
            ),
            a!richTextItem(
              text: {
                char(32),
                a!richTextItem(
                  text: {
                    joinarray(
                      {
                        index(ri!pagingInfo, "startIndex", null),
                        char(45),
                        if(
                          (
                            index(ri!pagingInfo, "startIndex", null) + index(ri!pagingInfo, "batchSize", null) - 1
                          ) > ri!totalCount,
                          ri!totalCount,
                          (
                            index(ri!pagingInfo, "startIndex", null) + index(ri!pagingInfo, "batchSize", null) - 1
                          )
                        )
                      },
                      char(32)
                    )
                  },
                  style: "STRONG"
                ),
                char(32),
                joinarray({ "of", ri!totalCount }, char(32)),
                char(32)
              }
            ),
            a!richTextIcon(
              icon: "chevron-right",
              link: a!dynamicLink(
                saveInto: a!save(
                  ri!pagingInfo,
                  a!pagingInfo(
                    startIndex: ri!pagingInfo.startIndex + ri!pagingInfo.batchSize,
                    batchSize: ri!pagingInfo.batchSize,
                    sort: ri!pagingInfo.sort
                  )
                ),
                showWhen: ri!pagingInfo.startIndex < ri!totalCount - ri!pagingInfo.batchSize
              ),
              linkStyle: "STANDALONE"
            )
          }
        )
      }
    )

  • 0
    Certified Senior Developer
    in reply to Maria

    This is the code I have for the editable grid:  I dont see how the paging is doing anything to the actual rows in the grid.

     

    a!localVariables(
      local!items: {
        {item: "Item 1", qty: 1, unitPrice: 10},
        {item: "Item 2", qty: 2, unitPrice: 20},
        {item: "Item 3", qty: 3, unitPrice: 30},
        {item: "Item 4", qty: 4, unitPrice: 40},
        {item: "Item 5", qty: 5, unitPrice: 50},
        {item: "Item 6", qty: 6, unitPrice: 60},
        {item: "Item 7", qty: 7, unitPrice: 70},
        {item: "Item 8", qty: 8, unitPrice: 80},
        {item: "Item 9", qty: 9, unitPrice: 90},
        {item: "Item 10", qty: 10, unitPrice: 100}
      },
      local!pagingInfo: a!refreshVariable(
        value: a!pagingInfo(
          startIndex: 1,
          batchSize: 5,
          sort: a!sortInfo(field: "item", ascending: false())
        )),
        local!dataSubset:todatasubset(local!items,local!pagingInfo),
      
    
     { a!gridLayout(
        label: "Products",
        instructions: "Update the item name, quantity, or unit price.",
        headerCells: {
          a!gridLayoutHeaderCell(label: "Item"),
          a!gridLayoutHeaderCell(label: "Qty"),
          a!gridLayoutHeaderCell(label: "Unit Price"),
          a!gridLayoutHeaderCell(label: "Total", align: "RIGHT")
        },
        columnConfigs: {
          a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 5),
          a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
          a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
          a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2)
        },
        rows: a!forEach(
          items: local!dataSubset,
          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
              ),
              a!textField(
                value: dollar(tointeger(fv!item.qty) * todecimal(fv!item.unitPrice)),
                readOnly: true,
                align: "RIGHT"
              )
            }
          )  
        ),
        height: "SHORT",
        rowHeader: 1
      ),
      rule!customPaginationRule(
        pagingInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: 4,
        ),
        totalCount: local!dataSubset.totalCount
      )}
    )

  • 0
    Certified Senior Developer
    in reply to Maria

    can you pass local!paginginfo in custom pagination rule and check

  • 0
    Certified Senior Developer
    in reply to Abhishek Karumuru

    still the same , I should see only first 4 rows in the first page I still see all items.

  • +1
    Certified Senior Developer
    in reply to Maria

    hi   could you try this whole code and check?

    a!localVariables(
      local!items: {
        {item: "Item 1", qty: 1, unitPrice: 10},
        {item: "Item 2", qty: 2, unitPrice: 20},
        {item: "Item 3", qty: 3, unitPrice: 30},
        {item: "Item 4", qty: 4, unitPrice: 40},
        {item: "Item 5", qty: 5, unitPrice: 50},
        {item: "Item 6", qty: 6, unitPrice: 60},
        {item: "Item 7", qty: 7, unitPrice: 70},
        {item: "Item 8", qty: 8, unitPrice: 80},
        {item: "Item 9", qty: 9, unitPrice: 90},
        {item: "Item 10", qty: 10, unitPrice: 100}
      },
      local!pagingInfo: a!refreshVariable(
        value: a!pagingInfo(
          startIndex: 1,
          batchSize: 5,
          sort: a!sortInfo(field: "item", ascending: false())
        )),
        local!dataSubset:todatasubset(local!items,local!pagingInfo),
    
    
        { a!gridLayout(
          label: "Products",
          instructions: "Update the item name, quantity, or unit price.",
          headerCells: {
            a!gridLayoutHeaderCell(label: "Item"),
            a!gridLayoutHeaderCell(label: "Qty"),
            a!gridLayoutHeaderCell(label: "Unit Price"),
            a!gridLayoutHeaderCell(label: "Total", align: "RIGHT")
          },
          columnConfigs: {
            a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 5),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 2)
          },
          rows: a!forEach(
            items: local!dataSubset,
            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
                ),
                a!textField(
                  value: dollar(tointeger(fv!item.qty) * todecimal(fv!item.unitPrice)),
                  readOnly: true,
                  align: "RIGHT"
                )
              }
            )  
          ),
          height: "SHORT",
          rowHeader: 1
        ),
        a!sectionLayout(
          contents: {
            a!richTextDisplayField(
              align: "RIGHT",
              value: {
                a!richTextIcon(
                  icon: "chevron-left",
                  link: a!dynamicLink(
                    saveInto: a!save(
                      local!pagingInfo,
                      a!pagingInfo(
                        startIndex: local!pagingInfo.startIndex - local!pagingInfo.batchSize,
                        batchSize: local!pagingInfo.batchSize,
                        sort: local!pagingInfo.sort
                      )
                    ),
                    showWhen: local!pagingInfo.startIndex > 1
                  ),
                  linkStyle: "STANDALONE"
                ),
                a!richTextItem(
                  text: {
                    char(32),
                    a!richTextItem(
                      text: {
                        joinarray(
                          {
                            index(local!pagingInfo, "startIndex", null),
                            char(45),
                            if(
                              (
                                index(local!pagingInfo, "startIndex", null) + index(local!pagingInfo, "batchSize", null) - 1
                              ) > local!dataSubset.totalCount,
                              local!dataSubset.totalCount,
                              (
                                index(local!pagingInfo, "startIndex", null) + index(local!pagingInfo, "batchSize", null) - 1
                              )
                            )
                          },
                          char(32)
                        )
                      },
                      style: "STRONG"
                    ),
                    char(32),
                    joinarray({ "of", local!dataSubset.totalCount }, char(32)),
                    char(32)
                  }
                ),
                a!richTextIcon(
                  icon: "chevron-right",
                  link: a!dynamicLink(
                    saveInto: a!save(
                      local!pagingInfo,
                      a!pagingInfo(
                        startIndex: local!pagingInfo.startIndex + local!pagingInfo.batchSize,
                        batchSize: local!pagingInfo.batchSize,
                        sort: local!pagingInfo.sort
                      )
                    ),
                    showWhen: local!pagingInfo.startIndex < local!dataSubset.totalCount - local!pagingInfo.batchSize
                  ),
                  linkStyle: "STANDALONE"
                )
              }
            )
          }
        )}
    )

  • +1
    Certified Lead Developer
    in reply to Maria

    It works for me when making the suggested correction.

    To clarify, you need to pass the local pagingInfo variable into your Paging handler rule - the way you currently have it hardcoded will make it useless.

    rule!customPaginationRule(
      pagingInfo: local!pagingInfo,
      totalCount: local!dataSubset.totalCount
    )

  • +1
    Certified Senior Developer
    in reply to Abhishek Karumuru

    Thanks! now with this the rows are displaying correctly.  Thank you very much for all the help!

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    correct, I also did this and it didn't work. But with the last code   provided is working. 

    Thanks to you too Mike!

  • 0
    Certified Lead Developer
    in reply to Maria
    But with the last code   provided is working. 

    The version I was able to get working still uses your external paging handler rule, though, if you were wanting to keep that.