Create the master view in an Oracle JET web app
Introduction
This tutorial discusses how to read master-detail hierarchical data from a local JavaScript Object Notation (JSON) document and display the data in a master view in an Oracle JavaScript Extension Toolkit (Oracle JET) web app.
In the viewModel for the Oracle JET web app, you can use the Oracle JET API to create a data provider object. The object represents a data array that you populate from the parent objects of a JSON document data store. In the view for the Oracle JET web app, the data attribute of Oracle JET custom HTML elements binds to the data through an instance of a MutableArrayDataProvider object that is declared and populated in the app’s viewModel source code.
Objectives
In this tutorial, you will data bind multiple items of the parent data objects in a local JSON document and populate the rows of an Oracle JET List View component with that data.
Prerequisites
- A development environment set up to create Oracle JET web apps that includes an installation of Node.js
- Google Chrome web browser installed and set as the default web browser
- Access to the Oracle JET Developer Cookbook
- (Option 1) Completion of the final tutorial in the previous learning path in this series: Test the Oracle JET Web Application on Different Screen Sizes
- (Option 2) If you haven’t completed the previous learning path in this series: The jet_web_application_temp.zip downloaded
- The product_images.zip downloaded to the
JET_Web_Application/src/css/images/directory
Task 1: Download the Starter App
Skip this task if you’re continuing to work in an app that you created in the previous learning path.
-
Rename
jet_web_application_temp.zipasJET_Web_Application.zip. Extract the contents to theJET_Web_Applicationfolder. -
Navigate to the
JET_Web_Applicationfolder, and restore the Oracle JET web app.npm installYour app is ready to use.
Task 2: Download the Product Images
Skip this task if you downloaded the starter app in jet_web_application_temp.zip.
-
If the Oracle JET tooling server batch job is running in the terminal window, press Ctrl+C, and if prompted, enter
yto exit the server batch job.The server batch job only recognizes revisions that you make to existing app files. After you create new files, you must run the web app again.
-
Download the
product_images.zipfile to theJET_Web_Application/src/css/imagesdirectory. -
Extract the content of the zip file into a new
product_imagesfolder in theimagesfolder.The path to the new folder is
JET_Web_Application/src/css/images/product_images, and the folder contains the images that your app uses.
Task 3: Enhance the Activities List in the View
Modify the Oracle JET List View component to display multiple data items of the Activities array data source for each list row. To instantiate the contents of the list row data items at runtime, the Activities List View component uses an HTML template element with a slot attribute as a placeholder.
-
Navigate to the
JET_Web_Application/src/ts/viewsdirectory and open thedashboard.htmlfile in an editor. -
Find the
divelement withid="activityItemsContainer", and delete theoj-sm-only-text-align-endhelper class to prevent realignment of the Activities list contents.<div id="activitiesContainer" class="oj-flex-item oj-bg-info-30 oj-md-4 oj-sm-12" ></div> -
Find the
oj-list-viewcustom HTML element whereid="activitiesList", and add aclassattribute with the valueitem-display.<oj-list-view id="activitiesList" class="item-display" aria-labelledby="activitiesHeader" data="[[activityDataProvider]]" gridlines.item="visible" ></oj-list-view>To supply the List View data source, the
dataattribute binds theactivityDataProviderobservable as a one-way data binding. -
In the
oj-list-viewelement whereid="activitiesList", find the template element whereslot="itemTemplate", and delete thedivelement and the containedoj-bind-textelement.<template slot="itemTemplate"> </template> -
In the empty
templateelement, add threedivelements with code to populate the List View component rows with a background image, name, and short description.<template slot="itemTemplate"> <div class="oj-flex no-wrap"> <span class="demo-thumbnail oj-flex-item" :style.background-image="[[' url('+$current.data.image+')']]" ></span> <div class="demo-content oj-flex-item"> <div> <strong> <oj-bind-text value="[[$current.data.name]]"></oj-bind-text> </strong> </div> <span class="demo-metadata"> <oj-bind-text value="[[$current.data.short_desc]]"></oj-bind-text> </span> </div> </div> </template> -
Save the
dashboard.htmlfile.Your file should look similar to final-master-list-dashboard-html.txt.
-
Navigate to the
JET_Web_Application/src/cssdirectory and open theapp.cssfile. Here you can add app-specific CSS styles. Create an.item-displaystyle definition withwidth,height, andoverflow-xproperties to support the display of multiple data items in the list rows..item-display { width: 100%; height: 500px; overflow-x: hidden; }
Task 4: Review the Activities Data Provider in the ViewModel
To populate the Activities List View component, the viewModel creates an instance of the Activities data array by using an Oracle JET MutableArrayDataProvider class. The JSON.parse method parses the local JSON data store as an argument that returns the data.
-
Open the Oracle JET Cookbook and navigate to the Cookbook Home page. Click Framework, then Data Provider, and then Mutable Array Data Provider. In the Cookbook toolbar, click API Doc.
-
In the API documentation, read about the
MutableArrayDataProviderclass. Note how you can use the optional argumentkeyAttributesto create an instance of anMutableArrayDataProviderclass based on the key attribute of the passed-in data object. -
Navigate to the
JET_Web_Application/src/ts/viewModelsdirectory and open thedashboard.tsfile in an editor. Find the declaration ofthis.activityDataProviderin the constructor method.this.activityDataProvider = new MutableArrayDataProvider< Activity["id"], Activity >(JSON.parse(storeData), { keyAttributes: "id", }); }This creates the
activityDataProviderobject, an instance of theMutableArrayDataProviderclass. ThekeyAttributesproperty ofMutableArrayDataProviderpopulates the Activities array based on theidattribute of the parent object. Theidattribute is the key attribute for parent and child data objects in the JSON document. -
Close the
dashboard.tsfile without making any changes.Your file should look similar to final-master-list-dashboard-ts.txt.
Task 5: Run the Web App and Debug the App’s Cascading Style Sheet
-
In the terminal window, change to the
JET_Web_Applicationdirectory and run the app.npx ojet serveOracle JET tooling runs your web app in a local web browser, where you can view the databound master list. The images displayed to the left of the Activities list activity names are only partially displayed because they’re too large.
If you resize your browser and still don’t see a page similar to this sample screenshot, confirm that you extracted the app images into the
product_imagesfolder.
-
In your Google Chrome browser, right-click the partial image for the Soccer activity and select Inspect. The browser displays developer tools for inspecting the HTML page source.
-
In the Elements panel, select the
span class="demo-thumbnail"element. In the Styles panel, locate the highlightedelement.style background-imagestyle. Right-click the URL for thejrsoccerball.jpgimage, and select Reveal in Sources panel.
-
The Chrome DevTools Sources panel shows that the image is 300 x 300 pixels, and the size is too large to be displayed in the Oracle JET List View component. To render a thumbnail-sized image from a full-sized image, you can define a Cascading Style Sheets (CSS) style class.

-
Close the developer tools window and return to the app in the browser.
Task 6: Fix the CSS and View the Master List
-
Navigate to the
JET_Web_Application/src/cssdirectory and open theapp.cssfile in an editor. -
Define the properties for the
.demo-thumbnailclass selector. In the list of properties, set abackground-repeatproperty tono-repeatto show the image only once. Also define ano-wrapclass selector with the propertyflex-wrapset tonowrap..demo-thumbnail { border-radius: 5px; background-size: 40px 40px; background-repeat: no-repeat; min-width: 40px; min-height: 40px; max-width: 40px; margin-right: 10px; } .no-wrap { flex-wrap: nowrap; }In the
dashboard.htmlfile, thespanelement references the class selector to format the Activities list image as a thumbnail by setting thedemo-thumbnailCSS style on theclassattribute. In thespanelement, thebackground-imageCSS property sets the image based on the URL in theimageproperty of the current Activity parent object.<span class="demo-thumbnail oj-flex-item" :style.background-image="[[' url('+$current.data.image+')']]" ></span> -
Save and close the
app.cssfile.Your file should look similar to app-css-final.txt.
-
In the web browser, reload the page.
The browser displays the databound master list with thumbnail-sized images.

-
Close the browser window or tab that displays your running web app.
-
In the terminal window, press Ctrl+C, and if prompted, enter
yto exit the Oracle JET tooling batch job.
Next Step
Proceed to the next tutorial in this module.
This tutorial is part of the module Master Detail Views in Oracle JET.
- Create the Master View in an Oracle JET Web App
- Create the Detail View in an Oracle JET Web App
- Handle Selection Events in an Oracle JET Web App
You can return to the learning path’s main page to access all the modules on building web apps.
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Create the master view in an Oracle JET web app
F11705-10