Hi, I have readable grid in which i am using arrow icon, so if I click on that arrow so that row should go up and upper row should come down. I can get all data items from current row, but how I will get data from previous row, So I can apply swapping conditiin
Discussion posts and replies are publicly visible
Hello shubhamsingh ,
Below code contains logic to move rows up and down.
{ a!localVariables( local!duplicate, local!removed, local!change, local!data: index( a!queryRecordType( recordType: 'recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company', filters: a!queryFilter( field: 'recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{19721518-b5ee-4deb-b4b2-5b0d5603d6ba}isActive', operator: "=", value: true ), pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 100) ), "data", null ), { a!gridLayout( label: "Editable Grid", labelPosition: "ABOVE", headerCells: { a!gridLayoutHeaderCell(label: "Company Name"), a!gridLayoutHeaderCell(label: "Postcode"), a!gridLayoutHeaderCell(label: "City"), a!gridLayoutHeaderCell(label: "State "), a!gridLayoutHeaderCell(label: "Remove"), a!gridLayoutHeaderCell(label: "Move Up"), a!gridLayoutHeaderCell(label: "Move Down") }, columnConfigs: {}, rows: a!forEach( items: local!data, expression: a!gridRowLayout( contents: { a!textField( value: fv!item['recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{c048e290-9f07-4fe7-a919-71b572004f35}companyName'], saveInto: fv!item['recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{c048e290-9f07-4fe7-a919-71b572004f35}companyName'] ), a!textField( value: fv!item['recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{07050c26-84c9-4749-8aa2-54675c403e0e}companyAddressPostCode'], saveInto: fv!item['recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{07050c26-84c9-4749-8aa2-54675c403e0e}companyAddressPostCode'] ), a!textField( value: fv!item['recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{9070d09a-ffd1-485b-9ac3-159cf5bed7ed}companyAddressCity'], saveInto: fv!item['recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{9070d09a-ffd1-485b-9ac3-159cf5bed7ed}companyAddressCity'] ), a!textField( value: fv!item['recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{80559642-a863-41e2-ad38-129e72546134}companyAddressState'], saveInto: fv!item['recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{80559642-a863-41e2-ad38-129e72546134}companyAddressState'] ), a!richTextDisplayField( value: a!richTextIcon( icon: if( fv!item['recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{19721518-b5ee-4deb-b4b2-5b0d5603d6ba}isActive'], "times", "check" ), caption: "click to add or remove company", link: a!dynamicLink( saveInto: if( fv!item['recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{19721518-b5ee-4deb-b4b2-5b0d5603d6ba}isActive'], { a!save( fv!item['recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{19721518-b5ee-4deb-b4b2-5b0d5603d6ba}isActive'], false() ) }, { a!save( fv!item['recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{19721518-b5ee-4deb-b4b2-5b0d5603d6ba}isActive'], true() ) } ) ), color: if( fv!item['recordType!{9e939d67-33c2-43f5-8030-51fe874a4980}PS Company.fields.{19721518-b5ee-4deb-b4b2-5b0d5603d6ba}isActive'], "NEGATIVE", "POSITIVE" ) ) ), a!richTextDisplayField( value: a!richTextIcon( showWhen: not(fv!isFirst), icon: "arrow-up", link: a!dynamicLink( value: fv!item, saveInto: { local!removed, a!save( local!change, index(local!data, fv!index - 1, null) ), a!save( local!data, insert(local!data, fv!item, fv!index - 1) ), a!save(local!data, remove(local!data, fv!index)), a!save( local!data, a!update(local!data, fv!index, local!change) ) } ) ) ), a!richTextDisplayField( value: a!richTextIcon( showWhen: not(fv!isLast), icon: "arrow-down", link: a!dynamicLink( value: fv!item, saveInto: { local!removed, a!save(local!data, remove(local!data, fv!index)), a!save( local!data, insert(local!data, local!removed, fv!index + 1) ) } ) ) ), } ) ) ), a!linkField( links: a!dynamicLink( label: "Add New Company", saveInto: { a!save( target: local!data, value: { append(local!data, "") } ) } ) ) } ) }
The OP must be using a gridField() and not a gridLayout()
shubhamsingh said:I have readable grid
Yes. I have worked on this logic already but for editable grid. I gave it for reference purpose just to move rows up and down.
Here is a much more optimized version of what you are trying to do for the editable grid.
a!save( ri!data, a!update( ri!data, { fv!index, fv!index + 1 }, { ri!data[fv!index + 1], fv!item } ) )