Hello Community,
I want to make an editable grid with fields having below details
Column Names - studentCountry , studentName, subject , status - (Pass or Fail)I've Created the grid where the studentName will be repeating and read only because of the different subjects & also subject will be read only-> the user (teacher) should fill the studentCountry and his status - (Pass or Fail) in editable grid,Now my requirement is such that when a teacher selects student country for a particular student it should update the studentCountry for all the rows having that particular student name.How should I achieve this. Any suggestion will helpful.Some sample data for better understanding studentCountry studentName subject status1) dropdown Student A Maths Yes/No (radio button)2) dropdown Student A Science Yes/No (radio button) 3) dropdown Student A English Yes/No (radio button)
4) dropdown Student B Maths Yes/No (radio button)5) dropdown Student B Science Yes/No (radio button) 6) dropdown Student B English Yes/No (radio button)
Thanks in advance.
Discussion posts and replies are publicly visible
load( local!student: { { id: 1, name: "Kelly", country: null }, { id: 2, name: "Jason", country: null }, { id: 3, name: "David", country: null } }, local!subject: { { subId: 1, studentId: 1, subject: "English", status: "" }, { subId: 2, studentId: 1, subject: "Science", status: "" }, { subId: 3, studentId: 1, subject: "Maths", status: "" }, { subId: 4, studentId: 2, subject: "English", status: "" }, { subId: 5, studentId: 2, subject: "Science", status: "" }, { subId: 6, studentId: 2, subject: "Maths", status: "" }, { subId: 4, studentId: 3, subject: "English", status: "" }, { subId: 5, studentId: 3, subject: "Science", status: "" }, { subId: 6, studentId: 3, subject: "Maths", status: "" } }, a!formLayout( contents: { a!gridLayout( headerCells: { a!gridLayoutHeaderCell(label: "Student"), a!gridLayoutHeaderCell(label: "Country"), a!gridLayoutHeaderCell(label: "Subject"), a!gridLayoutHeaderCell(label: "Status"),
}, columnConfigs: { a!gridLayoutColumnConfig(width: "DISTRIBUTE"), a!gridLayoutColumnConfig(width: "DISTRIBUTE"), a!gridLayoutColumnConfig(width: "DISTRIBUTE"), a!gridLayoutColumnConfig(width: "DISTRIBUTE") }, rows: a!forEach( items: local!subject, expression: a!localVariables( local!studentIndex: tointeger( wherecontains(fv!item.studentId, local!student.id) )[1], a!gridRowLayout( id: fv!index, contents: { a!textField( readOnly: true, value: local!student[wherecontains(fv!item.studentId, local!student.id)].name ), a!dropdownField( choiceLabels: { "country 1", "Country 2" }, choiceValues: { "country 1", "Country 2" }, placeholder: "Select Country", value: tostring( local!student[local!studentIndex].country ), saveInto: { local!student[local!studentIndex].country } ), a!textField(readOnly: true, value: fv!item.subject), a!dropdownField( choiceLabels: { "Pass", "Fail" }, choiceValues: { "Pass", "Fail" }, placeholder: "Select Status", value: fv!item.status ) } ) ) ) ) } ))
}, columnConfigs: { a!gridLayoutColumnConfig(width: "DISTRIBUTE"), a!gridLayoutColumnConfig(width: "DISTRIBUTE"), a!gridLayoutColumnConfig(width: "DISTRIBUTE"), a!gridLayoutColumnConfig(width: "DISTRIBUTE") }, rows: a!forEach( items: local!subject, expression: a!localVariables( local!studentIndex: tointeger( wherecontains(fv!item.studentId, local!student.id) )[1], a!gridRowLayout( id: fv!index, contents: { a!textField( readOnly: true, value: local!student[wherecontains(fv!item.studentId, local!student.id)].name ), a!dropdownField( choiceLabels: { "country 1", "Country 2" }, choiceValues: { "country 1", "Country 2" }, placeholder: "Select Country", value: tostring( local!student[local!studentIndex].country ), saveInto: { local!student[local!studentIndex].country } ), a!textField(readOnly: true, value: fv!item.subject), a!dropdownField( choiceLabels: { "Pass", "Fail" }, choiceValues: { "Pass", "Fail" }, placeholder: "Select Status", value: fv!item.status ) } ) ) ) ) }, buttons: a!buttonLayout( primaryButtons: { a!buttonWidget( label :"Submit", style:"PRIMARY", value:true, saveInto: { a!writeToMultipleDataStoreEntities( valuesToStore: { a!entityData( entity: cons!student_data_store_entity, data:local!student ), a!entityData( entity: cons!subject_data_store_entity, data:local!subject ) }, onSuccess: { a!save( local!student, fv!storedValues[1] ), a!save( local!subject, fv!storedValues[2] ) } ) }, ) } ) ))
on submit data will be written to database table.
Hello Jasmithak,
I was trying to change the field for this expression you've given in above code
local!studentIndex: tointeger(wherecontains(fv!item.studentId, local!student.id))[1],
due to some changes in my use case, It works fine for this field but as soon as I change the field, It throws me error saying :
Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!forEach [line 133]: Error in a!forEach() expression during iteration 1: Expression evaluation error : Invalid index (1) for list: valid range is empty
could you please explain me why are we using "[1]" as some sort of index ?Thanks in advance.
PK said:could you please explain me why are we using "[1]" as some sort of index ?
The function wherecontains() returns an ARRAY TYPE value regardless of how many entries it contains. Thus a common way to pre-correct the result (such as the variable you're storing the value into) is to use the "hardcoded", [1] index. This makes the assumption that there will always be at least one match to the wherecontains() call. If it would ever be possible for an empty set to be returned, it would be better to use index(), i.e.
index(wherecontains(fv!item.studentId, local!student.id), 1, null())
... which will attempt to get "index 1" of the resulting array, if applicable, and if the resuling array has no "index 1", it will return the fallback value of "null()".
Thanks Mike, I got it now.
Able to fix the issue. need any help?
Yes was able to fix it. Thanks for help