Editable Grid : update common Fields

Certified Associate Developer

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        status
1)   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

Parents
  • 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
    )
    }
    )
    )
    )
    )
    }
    )
    )

  • 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
    )
    }
    )
    )
    )
    )
    },
    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.

Reply
  • 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
    )
    }
    )
    )
    )
    )
    },
    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.

Children