Add sub-categories in a table with an option to change them #10664
-
Hello everyone, I want to create a table with a certain row having sub-categories. The issue is they are not fixed and the user should have an option of changing these sub-categories. Is this possible? Please find below, for example the teachers should be able to change the courses and the associated percentages. Can someone please guide me what to do? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @BismaIftekhar This is an interesting use-case - thank you for the diagram! It was fairly complicated, but I was able to come up with a solution using the community Super Table by @poirazis in combination with the Budibase JSON data type. Step 1 - Create the Data tableCreate a new table called Scores to keep track of the marks for each attribute, i.e. Attendance, Behaviour, Courses. This tutorial won't cover relationships, but most likely you would want to link this table to your Teachers table. Create a JSON type column called Attributes. Click {
"name": "Courses",
"subcat1": "Math",
"submarks1": 20,
"subcat2": "English",
"submarks2": 30,
"subcat3": "Language",
"submarks3": 20,
"subcat4": "Technical Skills",
"submarks4": 10,
"marks": 100,
"hasSubCategories": true
} The Form tab should appear as follows: Make sure to You will notice from the schema that we have hard-coded four sub-categories. This is a bit of a limitation in that you need to know the number of attributes ahead of time. There is an open feature request for handling dynamic form inputs: #5658 Also note the hasSubCategories property. This will determine if the sub-category fields should be shown or not. Step 2 - Adding the Super TableMake sure you have imported the SuperTable plugin as well as the companion Super Column and Super Cell plugins. More information can be found in the custom plugins docs. Next add the necessary components to your screen:
Step 3 - Adding the form fieldsWith the table structure setup, we need to add in the form fields to allow the sub categories and marks to be edited. Within the sub category column component, nest a Form component and select the Scores table as the Schema. Assign a field for each from the dropdown, for example: Also assign the correct default value. For example: Another step we need to do is only showing the field group and save icon if hasSubCategories is set. We do this through Conditional UI. Click on the container component, and select the Conditions tab from the settings panel. Click With the sub categories done, follow similar steps for the marks form fields. There are a couple of differences: use Number fields instead of text fields, and within the container have one field called Marks, and below a field group for the sub-category marks. At the end your component tree should look similar to the following: Step 4 - Saving the fieldsThe final step is to make the save icons update the existing JSON with the newly entered data. Click on the Save icon component for the sub-categories form and click Use the The JavaScript binding is as follows: return {
...$("Sub Category Column.Cell Value"),
subcat1: $("Sub Form.Fields.Attributes.subcat1"),
subcat2: $("Sub Form.Fields.Attributes.subcat2"),
subcat3: $("Sub Form.Fields.Attributes.subcat3"),
subcat4: $("Sub Form.Fields.Attributes.subcat4"),
} Here we are taking the existing attributes data and updating the subcat 1-4 fields with the form fields. The Save Row action for the Marks form will be very similar, just different form fields: JavaScript binding: let cellVal = $("Marks Column.Cell Value")
if (cellVal.hasSubCategories) {
return {
...cellVal,
submarks1: $("Marks Form.Fields.Attributes.submarks1"),
submarks2: $("Marks Form.Fields.Attributes.submarks2"),
submarks3: $("Marks Form.Fields.Attributes.submarks3"),
submarks4: $("Marks Form.Fields.Attributes.submarks4"),
}
}
return {
...cellVal,
marks: $("Marks Form.Fields.Attributes.marks")
} There's a little but of logic here to determine if the marks are for sub-categories or the main category. ResultApp export: |
Beta Was this translation helpful? Give feedback.
-
Hello @melohagan another question please if you could help. "How to retrieve data from a public form with dynamic entries?" So, Step 1: Step2: Question: Once that data is written in the table, teachers should then be able to grade them too. Any help would be appreciated. |
Beta Was this translation helpful? Give feedback.
Hey @BismaIftekhar
This is an interesting use-case - thank you for the diagram!
It was fairly complicated, but I was able to come up with a solution using the community Super Table by @poirazis in combination with the Budibase JSON data type.
Step 1 - Create the Data table
Create a new table called Scores to keep track of the marks for each attribute, i.e. Attendance, Behaviour, Courses.
This tutorial won't cover relationships, but most likely you would want to link this table to your Teachers table.
Create a JSON type column called Attributes. Click
Open schema editor
and provide the following JSON schema: