Skip to main content
pranavk513898
February 7, 2022
Question

Editable Grid : update common Fields

  • February 7, 2022
  • 15 replies
  • 0 views

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.

    15 replies

    mikes0011
    Brainy
    February 7, 2022

    There are various potential approaches to this, but choosing which approach really kinda depends on the structure of your CDT and how you're using it in your interface.  For example.. is the "student country" data really duplicated across every row of student/subject data?  Or is it kept separate somewhere (i.e. just relative to a single Student entry)?

    The Expression Guru
    pranavk513898
    February 7, 2022

    Thank you Mike for the quick reply,

    well this ain't my actual scenario but justifies what I want to do with the grid,
    So in my actual use case I am using view which is formed using  two tables as the data for editable grid,


    So based on that for above data you can say studentCountry and studentName will be kept unique in "student data" table and the subject & status will be coming from some another table "subject status" table

    "student data" table is going to have one to many relationship with  "subject status" table.

    Thanks in advance.

    gopalk2865
    Participating Frequently
    February 8, 2022

    Hi, So I assume that initially country field is blank and in grid also it will be showing as blank. In this case ,once user selects any value from country drop-down,you can use write to data store entity smart service in save into of this field or you can have this data in a local variable and once user submits the form you can update all data at once in process model.

    pranavk513898
    February 8, 2022

    Yeah that's correct But I want to handle it on interface level and just pass rule inputs to process model to update my tables.

    Thank you.

    February 8, 2022

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

    pranavk513898
    February 8, 2022

    Thank you jasmithak990

    Above code does exactly what I want, the only issue I am facing is how to save this data in rule input which I'll be passing in process model to update my tables.

    thanks again.

    mikes0011
    Brainy
    February 8, 2022

    When implemented in a "real" task as opposed to an example that anyone can copy and paste, generally you would be acting directly upon the student data (i.e. via "ri!student"), rather than in a local variable.  Sometimes it's necessary to do such processing on a local variable instead, and in those cases you can simply save the contents of the local variable back into the rule input when the user clicks the Submit button.

    The Expression Guru