How to reset the paging subdataset to avoid error on a master/detail grid ?

Certified Senior Developer

Hi,

I'm using a master/detail pattern with 2 grids, and I can observe an error when on the detail Grid I click Next paging (ex: set to "5-8 of 10") before to click on another row of the master grid.

ERROR : "Interface Definition: Expression evaluation error at function a!gridField [line 74]: A grid component [label=""] has an invalid value for "value" and "totalCount". "startIndex" must not be greater than "totalCount", but "startIndex" was 5 and "totalCount" was 1."

After browsing the forum I've read that I need to reset the paginginfo because the datasubset keeps the previous values.

Could you tell what to add or change in my code example to make it working please ? 

{
  a!localVariables(
    
    local!pagingCustomers: a!pagingInfo(
      startIndex: 1,
      batchSize: 4
    ),
    local!customers: rule!CJT2_GetCustomersWithFilters(
      id: null,
      pagingInfo: local!pagingCustomers
    ),
    local!selectedCustomer: null,

    local!pagingContacts: a!pagingInfo(
      startIndex: 1,
      batchSize: 4
    ),
    local!contacts: rule!CJT2_GetContactsWithFilters(
      customerId: local!selectedCustomer.id,
      pagingInfo: local!pagingContacts
    ),

    {
      a!columnsLayout(
        columns: {
          a!columnLayout(
            contents: {
              a!sectionLayout(
                label: "Customers",
                contents: {
                  a!gridField(
                    data: local!customers,
                    pagingSaveInto: local!pagingCustomers,
                    columns: {
                      a!gridColumn(
                        label: "Id",
                        value: fv!row.id
                      ),
                      a!gridColumn(
                        label: "Name",
                        value: fv!row.name
                      ),
                      a!gridColumn(
                        label: "Test",
                        value: fv!row.test
                      )
                    },
                    /*pageSize: 7,*/
                    selectable: true,
                    selectionStyle: "ROW_HIGHLIGHT",
                    selectionValue: index(local!selectedCustomer, "id", {}),
                    selectionSaveInto: {
                      /* This save replaces the value of the previously selected item with that of the newly selected item, ensuring only one item can be selected at once.*/
                      a!save(
                        local!selectedCustomer,
                        if(
                          length(fv!selectedRows) > 0,
                          fv!selectedRows[length(fv!selectedRows)],
                          null
                        )
                      )
                    },
                    shadeAlternateRows: false,
                    rowHeader: 1
                  ),
                  a!sectionLayout(
                    label: "Contacts",
                    contents: {
                      a!columnsLayout(
                        columns: {
                          a!columnLayout(
                            contents: {
                              a!gridField(
                                data: local!contacts,
                                pagingSaveInto: local!pagingContacts,
                                columns: {
                                  a!gridColumn(
                                    label: "Id",
                                    value: fv!row.id
                                  ),
                                  a!gridColumn(
                                    label: "Name",
                                    value: fv!row.name
                                  ),
                                  a!gridColumn(
                                    label: "Customer Id",
                                    value: fv!row.fk_customer_id
                                  )
                                },
                                /*pageSize: 7,*/
                                selectable: true,
                                selectionStyle: "ROW_HIGHLIGHT",
                                selectionValue: index(local!selectedCustomer, "id", {}),
                                selectionSaveInto: {
                                  /* This save replaces the value of the previously selected item with that of the newly selected item, ensuring only one item can be selected at once.*/
                                  a!save(
                                    local!selectedCustomer,
                                    if(
                                      length(fv!selectedRows) > 0,
                                      fv!selectedRows[length(fv!selectedRows)],
                                      null
                                    )
                                  )
                                },
                                shadeAlternateRows: false,
                                rowHeader: 1
                              ),  
                            }
                          ),
                        },
                        showWhen: true
                      )
                    }
                  )
                }
              )
            }
          ),
          
        }
      )
    }
  )
}          

  Discussion posts and replies are publicly visible

Parents
  • You should reset paging info every time local!selectedCustomer gets updated. First, move local!selectedCustomer above local!pagingCustomers in your list, then use a!refreshVariable

    a!localVariables(
        local!selectedCustomer: null,
        local!pagingCustomers: a!refreshVariable(
            value: a!pagingInfo(1,4),
            refreshOnVarChange: {local!selectedCustomer}
        )
    )

  • +1
    Certified Senior Developer
    in reply to Danny Verb

    Thank you Danny, but the problem is still there. Am I forgetting something else ?

      a!localVariables(
       
        local!selectedCustomer: null,
        local!pagingCustomers: a!refreshVariable(
          value: a!pagingInfo(1,4),
          refreshOnVarChange: {local!selectedCustomer}
        ),
        
        local!customers: rule!CJT2_GetCustomersWithFilters(
          id: null,
          pagingInfo: local!pagingCustomers
        ),
    
        local!pagingContacts: a!pagingInfo(
          startIndex: 1,
          batchSize: 4
        ),
        local!contacts: rule!CJT2_GetContactsWithFilters(
          customerId: local!selectedCustomer.id,
          pagingInfo: local!pagingContacts
        ),
        
        ...

  • +1
    Certified Lead Developer
    in reply to cedric01

    I think you need to do that change to your pagingContacts variable instead.  That's the paging information that becomes invalid if paged ahead prior to a different Customer being picked.

    As an alternative I'd suggest you could just add a manual override to the selectionSaveInto of your top grid, that pushes a value of "1" into local!pagingContacts.startIndex, which would have the same effect except also wouldn't reset your current sorting on the bottom grid.

    selectionSaveInto: {
      /* This save replaces the value of the previously selected item with that of the newly selected item, ensuring only one item can be selected at once.*/
      a!save(
        local!selectedCustomer,
        if(
          length(fv!selectedRows) > 0,
          fv!selectedRows[length(fv!selectedRows)],
          null
        )
      ),
      a!save(
        local!pagingContacts.startIndex,
        1
      )
    },

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    You're right, it works now ! :-)

    Thanks a lot Mike (I keep your tip too).

Reply Children