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
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} ) )
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 ), ...
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 ) },
You're right, it works now ! :-)
Thanks a lot Mike (I keep your tip too).
The other thing I noticed here is that you're using manual paging to set up your grid - did you try to directly embed your rule in the data parameter and run your query that way? Usually that's easier and if there is a change in the filtering and you're using fv!pagingInfo, it should automatically reset to a start index of 1 without you needing to do it here.
Thanks a lot for this tip Peter. I will take a look at it.
I was indeed, very surprised to have to do it manually.
Peter, I have tested your solution and it works fine.
Do you confirm me that in this way, the page size (I mean the number of records displayed in the grid) is from now set with the grid "pageSize" attribute and not the a!pageInfo please ?
Yes, one of the features of the new Read-Only Grid (the current a!gridField()) introduced in 19.2 is that when it manages its own paging, it safely ensures that paging is reset as necessary whenever its internal query is adjusted to show different results - i don't know if they publish the low-level specifics of this, but as far as I've tested, it works well when applicable.
Thank you Mike for this precision. That is a good future to avoid workarounds.