add dynamic number of models, tables, and/or includes?

  • 1
  • Question
  • Updated 2 years ago
  • Answered
Brainstorm needed!

I have a situation where I'm trying to add a set pool of students to a handful of classes. Each student from the pool can be added to any of the classes.

The big challenge is that depending on some variables, the number of classes is unknown, and can range anywhere from 2-10.

Luckily, the classes don't really need to have their own functionality, just display a list of the students added and refresh when a new student is added.

Any ideas on the best way to handle this? My current idea is to build a single class page, then include it 10 times in an assignment page, setting the query string dynamically via javascript for each one. This limits my need to maintain 10 identical tables, but also seems clunky.

Other ideas I've had:
- Dynamically build each model. The problem here is that I also need to dynamically build each table, or hack the xml to create references that don't yet exist, which is a bit of a pain.

- Create one table, sort by class, and try to use CSS or some Skuid functionality I don't know to break it up into multiple tables.

Anyone got any ideas?

Thanks,
Seth
Photo of Seth Leonard

Seth Leonard

  • 662 Points 500 badge 2x thumb

Posted 2 years ago

  • 1
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
Hi Seth, can you elaborate a little on your data map? It sounds like you might be using a junction object to connect students and classes. If the classes don't need their own identity, are they being, or could they be stored as multiselect picklist options on the Student object?
Photo of Seth Leonard

Seth Leonard

  • 662 Points 500 badge 2x thumb
Mark,

Setting the class is not the hard part, it's displaying a table for each class. You're right that there is a Course Assignment junction object. I basically need to display X number of tables, one for each class.

I'm currently working on building a custom table view that uses divs and closes them whenever a new course appears in the table (I'm sorting the Course Assignments based on course). I'm hopeful it'll work.

Open to better ideas, though. :)

Seth
Photo of JD Bell

JD Bell, Senior Product Engineer

  • 2,996 Points 2k badge 2x thumb
If I understand you correctly, then I think you'd want:
  • A "Classes" Model, and a Deck component to go with it.
  • A "StudentAssignment" Model, and a Table component within the Deck to go with it.
Use the Table's "Context" tab to set conditions on the table to only show the assignments associated with the "current" class (one class per card within the deck).

The assignment record would, presumably, include a reference to the student, and you could display that reference field in the table.

The end result would be a dynamic number of tables (one table for each class) showing you all the students assigned to each class. You could add a Page Title above each table to display the class name.

Below is an example using standard Salesforce objects.

You could take it a step further. Reference fields allow you to specify custom filters. You could add a "StudentPool" Model and then force the reference field on the "StudentAssignment" Model to select one of students in that model via a "in" condition.
  1. Click on the Student reference field in the table (we'll call it "StudentId")
  2. Choose the "Filters" tab
  3. Add a new Lookup Filter
  4. Choose "Field from another model" for the "Content"; "in" for the "Operator"; "StudentId" for the "Field"; "StudentPool" for the "Source Model"; and "Id" for the "Source Field".
The user will be able to use each class table to assign students by creating a new "StudentAssignment" record and selecting one of the students from the pool.

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">    <models>
        <model id="Accounts" limit="20" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="Account">
            <fields>
                <field id="Id"/>
                <field id="Name"/>
            </fields>
            <conditions/>
            <actions/>
        </model>
        <model id="Opportunities" limit="20" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="Opportunity">
            <fields>
                <field id="AccountId"/>
                <field id="Account.Name"/>
                <field id="Name"/>
                <field id="Description"/>
            </fields>
            <conditions/>
            <actions/>
        </model>
    </models>
    <components>
        <deck searchmethod="server" searchbox="true" columngutter=".75em" rowgutter=".75em" model="Accounts" filtersposition="top" filterswidth="150px" showsavecancel="false" behavior="flex" verticalalign="top" ratio="1" minwidth="350px" uniqueid="sk-22ofpw-134" buttonposition="" pagesize="10">
            <components>
                <pagetitle model="Accounts" uniqueid="sk-22oozP-164">
                    <maintitle>
                        <template>{{Name}}</template>
                    </maintitle>
                    <actions/>
                </pagetitle>
                <skootable showconditions="true" showsavecancel="true" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Opportunities" buttonposition="" mode="read" allowcolumnreordering="true" uniqueid="sk-22oiLD-146">
                    <fields>
                        <field id="Name" hideable="true" uniqueid="fi-22or-8-169" valuehalign="" type=""/>
                        <field id="Description" hideable="true" uniqueid="fi-22osoc-179" valuehalign="" type=""/>
                    </fields>
                    <rowactions>
                        <action type="edit"/>
                        <action type="delete"/>
                    </rowactions>
                    <massactions usefirstitemasdefault="true">
                        <action type="massupdate"/>
                        <action type="massdelete"/>
                    </massactions>
                    <views>
                        <view type="standard"/>
                    </views>
                    <conditions>
                        <condition type="contextrow" field="AccountId" mergefield="Id" operator="="/>
                    </conditions>
                </skootable>
            </components>
            <massactions/>
            <interactions/>
            <actions/>
        </deck>
    </components>
    <resources>
        <labels/>
        <javascript/>
        <css/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>
(Edited)
Photo of Seth Leonard

Seth Leonard

  • 662 Points 500 badge 2x thumb
JD - I'd never used a Deck component before and didn't know it existed. It's *exactly* what I need and I've got it working already. Thank you! Way better than a custom view.