If any of you have seen the functionality in User Start Pages, I want to implement the functionality to move a line of the editable grid up or down. I think I can do it via a dynamic link but it seems like possibly an expression rule may be an easier way? I looked around for examples and recipes and was not able to see any.
Anyone have any guidance on this? Any resources I could use to find an example for next steps?
Thanks!
Discussion posts and replies are publicly visible
Hi Sarah,
Please try the below code snippet,
load( local!employees: { { id: 1, firstName: "John", lastName: "Smith", department: "Engineering", title: "Director", phoneNumber: "555-123-4567", startDate: today() - 360 }, { id: 2, firstName: "Michael", lastName: "Johnson", department: "Finance", title: "Analyst", phoneNumber: "555-987-6543", startDate: today() - 360 }, { id: 3, firstName: "Mary", lastName: "Reed", department: "Engineering", title: "Software Engineer", phoneNumber: "555-456-0123", startDate: today() - 240 }, }, with( a!formLayout( label: "Grid Data", contents: { a!gridLayout( totalCount: count( local!employees ), headerCells: { a!gridLayoutHeaderCell( label: "First Name" ), a!gridLayoutHeaderCell( label: "Last Name" ), a!gridLayoutHeaderCell( label: "Department" ), a!gridLayoutHeaderCell( label: "Title" ), a!gridLayoutHeaderCell( label: "Phone Number" ), a!gridLayoutHeaderCell( label: "Start Date", align: "RIGHT" ), a!gridLayoutHeaderCell( label: "" ), a!gridLayoutHeaderCell( label: "" ), a!gridLayoutHeaderCell( label: "" ) }, columnConfigs: { a!gridLayoutColumnConfig( width: "DISTRIBUTE", weight: 3 ), a!gridLayoutColumnConfig( width: "DISTRIBUTE", weight: 3 ), a!gridLayoutColumnConfig( width: "DISTRIBUTE", weight: 3 ), a!gridLayoutColumnConfig( width: "DISTRIBUTE", weight: 3 ), a!gridLayoutColumnConfig( width: "DISTRIBUTE", weight: 3 ), a!gridLayoutColumnConfig( width: "DISTRIBUTE", weight: 2 ), a!gridLayoutColumnConfig( width: "ICON" ), a!gridLayoutColumnConfig( width: "ICON" ), a!gridLayoutColumnConfig( width: "ICON" ) }, rows: a!forEach( items: local!employees, expression: a!gridRowLayout( contents: { a!textField( label: "first name " & fv!index, value: fv!item.firstName, saveInto: fv!item.firstName, required: true ), a!textField( label: "last name " & fv!index, value: fv!item.lastName, saveInto: fv!item.lastName, required: true ), a!dropdownField( label: "department " & fv!index, placeholderLabel: "-- Select -- ", choiceLabels: { "Corporate", "Engineering", "Finance", "Human Resources", "Professional Services", "Sales" }, choiceValues: { "Corporate", "Engineering", "Finance", "Human Resources", "Professional Services", "Sales" }, value: fv!item.department, saveInto: fv!item.department, required: true ), a!textField( label: "title " & fv!index, value: fv!item.title, saveInto: fv!item.title, required: true ), a!textField( label: "phone number " & fv!index, placeholder: "555-456-7890", value: fv!item.phoneNumber, saveInto: fv!item.phoneNumber ), a!dateField( label: "start date " & fv!index, value: fv!item.startDate, saveInto: fv!item.startDate, required: true, align: "RIGHT" ), a!imageField( label: "delete " & fv!index, images: a!documentImage( document: a!iconIndicator( "MOVE_UP" ), altText: "Up", caption: "Move Up " & fv!item.firstName, link: a!dynamicLink( value: fv!index, saveInto: { if( fv!index = 1, {}, { a!save( local!employees, insert( local!employees, fv!item, fv!index - 1 ) ), a!save( local!employees, remove( local!employees, fv!index + 1 ) ) } ) } ) ), size: "ICON" ), a!imageField( label: "delete " & fv!index, images: a!documentImage( document: a!iconIndicator( "MOVE_DOWN" ), altText: "Down", caption: "Move Down " & fv!item.firstName, link: a!dynamicLink( value: fv!index, saveInto: { if( fv!index = count( local!employees ), {}, { a!save( local!employees, insert( local!employees, fv!item, fv!index + 2 ) ), a!save( local!employees, remove( local!employees, fv!index ) ) } ) } ) ), size: "ICON" ), a!imageField( label: "delete " & fv!index, images: a!documentImage( document: a!iconIndicator( "REMOVE" ), altText: "Remove Employee", caption: "Remove " & fv!item.firstName & " " & fv!item.lastName, link: a!dynamicLink( value: fv!index, saveInto: { a!save( local!employees, remove( local!employees, save!value ) ) } ) ), size: "ICON" ) }, id: fv!index ) ), addRowlink: a!dynamicLink( label: "Add Employee", value: { startDate: today() + 1 }, saveInto: { a!save( local!employees, append( local!employees, save!value ) ) } ), rowHeader: 1 ) } ) ) )
Thanks!!!
Regards,
Hema
Hema, Thank you so much for posting this! I've been looking for a quick way to reorder CDTs in this way and your solution was exactly what I needed.
Gil