Hi,
Well I have and editable grindLayout and I'm trying to add to a grindField the selected rows, but in editable grid we can't use fv!rowselected.
How can I do it?
Here's my code.
a!localVariables( local!items: { {item: "Juan", Apellido: "Muñoz", Provincia: "Madrid", Tlf: 678299336}, {item: "Jose", Apellido: "Perez", Provincia: "Alicante", Tlf: 999888777}, {item: "Pepito", Apellido: "Grillo", Provincia: "Sevilla", Tlf: 999888333}, {item: "Rodolfo", Apellido: "Chiquilicuatre", Provincia: "Granada", Tlf: 333444555}, {item: "Alfonso", Apellido: "Muñoz", Provincia: "Madrid", Tlf: 678299336}, {item: "Juan", Apellido: "Perez", Provincia: "Alicante", Tlf: 999888777}, {item: "Jose", Apellido: "Grillo", Provincia: "Sevilla", Tlf: 999888333}, {item: "Pepito", Apellido: "Chiquilicuatre", Provincia: "Granada", Tlf: 333444555}, {item: "Rodolfo", Apellido: "Muñoz", Provincia: "Madrid", Tlf: 678299336}, {item: "Alfonso", Apellido: "Perez", Provincia: "Alicante", Tlf: 999888777}, {item: "Juan", Apellido: "Grillo", Provincia: "Sevilla", Tlf: 999888333}, {item: "Jose", Apellido: "Chiquilicuatre", Provincia: "Granada", Tlf: 333444555}, {item: "Pepito", Apellido: "Muñoz", Provincia: "Madrid", Tlf: 678299336}, {item: "Rodolfo", Apellido: "Perez", Provincia: "Alicante", Tlf: 999888777}, {item: "Alfonso", Apellido: "Grillo", Provincia: "Sevilla", Tlf: 999888333}, }, local!selected: tointeger({}), local!selectedPersonas, local!pagingInfo: a!pagingInfo( startIndex: 1, batchSize: 5, ), with(local!datasubset: todatasubset( local!items, local!pagingInfo ), local!dataForCurrentPage: local!datasubset.items, { a!gridLayout( label: "Nombres", instructions: "Seleccionados: " & local!selected & local!selectedPersonas, headerCells: { a!gridLayoutHeaderCell(label: "Nombre"), a!gridLayoutHeaderCell(label: "Apellido", align: "RIGHT"), a!gridLayoutHeaderCell(label: "Provincia", align: "RIGHT"), a!gridLayoutHeaderCell(label: "Telefono", align: "RIGHT") }, rows: a!forEach( items: local!datasubset.data, expression: a!gridRowLayout( id: fv!index, contents: { a!textField( value: fv!item.item, saveInto: ri!persona.nombre ), a!textField( value: fv!item.Apellido, saveInto: ri!persona.apellido, align: "RIGHT" ), a!textField( value: fv!item.Provincia, saveInto: ri!persona.provincia, align: "RIGHT" ), a!integerField( value: fv!item.Tlf, saveInto: ri!persona.telefono, align: "RIGHT" ) } ) ), selectionValue: local!selected, /* Flatten the selected values so the result is easier to work with */ /* when the select/deselect all option is used in an editable grid */ selectionSaveInto: {a!save(local!selected, a!flatten(save!value)), a!save(local!selectedPersonas, fv!selectedRows)}, selectable: true, rowHeader: 1 ), a!gridField( label: "Seleccionados", ), a!richTextDisplayField( 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, ) ), showWhen: local!pagingInfo.startIndex > 1 ), linkStyle: "STANDALONE" ), a!richTextItem( text: { char( 32 ), a!richTextItem( text: { joinarray( { property( local!pagingInfo, "startIndex" ), char( 45 ), property( local!pagingInfo, "startIndex" ) + property( local!pagingInfo, "batchSize" ) - 1 }, char( 32 ) ) }, style: "STRONG" ), char( 32 ), joinarray( { "of", count( local!items ) }, 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, ) ), showWhen: local!pagingInfo.startIndex < count( local!items ) - local!pagingInfo.batchSize ), linkStyle: "STANDALONE" ) }, align: "RIGHT" ), } ), )
Thank you
Discussion posts and replies are publicly visible
I think the best way to achieve this is to use the value you have saved into your local variable to directly index into your source data. For example, you should be able to do something like this:
selectionSaveInto: { a!save( target: local!selected, value: a!flatten(save!value) ), a!save( local!selectedPersonas, index( local!datasubset.data, local!selected, {} ) ) },
That works!! Thank you!! But when I go to the next page, the selection box doesnt come empty, so I can't choose that values. The problem now is that i cant refresh selection vales, they always be between 1-5. How can I do that?
The best way to manage that is to use an identifier from your data as the grid row identifier. Currently, you're using the index of the a!forEach() function, which will always give you 1-5. However, suppose you had another field in your items variable for id. Then, in your grid row layout would be something like this:
rows: a!forEach( items: local!datasubset.data, expression: a!gridRowLayout( id: fv!item.id, contents: { ...
It works if check individuals checkboxes, but if I press the "select all" checkbox it overwrites all I have selected before
I got it to work by adding a null check on saving into selectedPersonas:
selectionSaveInto: { a!save( target: local!selected, value: a!flatten(save!value) ), a!save( local!selectedPersonas, if( or( isnull(local!selected), length(local!selected) < 1 ), {}, index( local!datasubset.data, local!selected, {} ) ) ) },
It doesn't work to me, I mean, when you select all in the first page and you go to the second and click select all again, all data selected in the 1st page desappeared.
I have done 2 an append and an union to have all data but i cant remove selected options. Here's the code.
selectionSaveInto: { a!save( target: local!selection, value: append(local!selection, save!value) ), a!save(target: local!selection, value: union(local!selection, local!selection)), a!save( target: local!selectedPersonas, value: if( length( local!selection ) = 0, null, index( local!items, local!selection, {} ) ) ) },
Honestly it gets confusing for end users anyway if you are selecting rows on multiple pages - you might want to consider other ways about designing this that could work better. For instance, what if you had "ADD" and "REMOVE" buttons on the toolbar? Then, when you select a row, users can click the button to add / remove them to / from the array. Or, what if you had an icon on each row for add? Then you could still add with one click without needing the selection column.