SlideShare a Scribd company logo
1 of 53
MWLUG 2013
Living on the Grid – Unlock the Power of
Dojo Data Grids (AD104)
Brad Balassaitis, PSC Group
Brad Balassaitis
• Notes/Domino developer for 17 years, XPages 3+ years
• Senior Consultant at PSC Group
– XPages Developer
– Project Lead
• Contact Information
– Blog: xcellerant.net
– Twitter: @Balassaitis
– LinkedIn: linkedin.com/in/bradbalassaitis
Agenda
• Dojo Data Grid Control
– Creation and Default Features
• Dojo Data Grid – Additional Features
– Sorting, Opening Docs, Searching, Editing
• Dojo EnhancedGrid
– Conversion
– Plugins
• Dojo TreeGrid
– Categorization
– Counts and Totals
Dojo Data Grid Control
• Availability
– Extension Library
– 8.5.3 Upgrade Pack 1
– Notes 9
• Creates a Dojo DataGrid
Why use the Dojo Data Grid?
• It’s not a view panel
• Feature-rich
– Adjustable columns, storing, editing, and much more
• Dojo is already on the Domino server
• Enhanced plugins are available
Creating a Dojo Data Grid
1. Create REST Service to provide data
2. Add the Dojo Data Grid control and bind to the REST service
3. Add Dojo Data Grid Columns
REST Service
• REST is a standard for client-server data exchange on the web
• Common method for providing data to a grid
• REST Service Control (ExtLib, 8.5.3 UP1, Notes9)
– Data Access > REST Service
REST Service - Creation
1. Add REST Service control to the page
2. Select the service type
– basics > service > + > xe:viewJsonService
3. Set the contentType to application/json
– basics > service > contentType
4. Select the view
– basics > service > viewName
5. Set defaultColumns to true
– basics > service > defaultColumns
REST Service - Customization
• Compute columns
• System columns
• Roll your own
REST Service - Verification
• Set pathInfo
– All Properties > basics > pathInfo
• Test it
– Server.com/dbname.nsf/XPage.xsp/pathInfoName
Creating a Dojo Data Grid
1. Create REST Service to provide data
2. Add the Dojo Data Grid control and bind to the REST service
3. Add Dojo Data Grid Columns
Default Grid Features
• Infinite scrolling
• Adjustable column widths
• Row highlighting
• Extended selection mode
• Sortable columns
• Multiple row entries
Additional Grid Properties
• rowSelector
• autoHeight
• rowsPerPage
• escapeHTMLInData
• loadingMessage
• errorMessage
• dir
Dojo Attributes
• More grid features are available, but not via properties
– e.g. Column Reordering, Grid Width
• Dojo > Dojo attributes
– or
• All Properties > dojo > dojo attributes
Column Reordering
• Allows user to rearrange columns
• Set via dojo attribute
Column Reordering
• Alternate method of setting attribute
Grid Width
• By default, takes up width of containers
• autoWidth attribute sizes to the required width
• Set via dojo attribute
Grid Column Properties
• label
• width
• hidden
• editable
• formatter
– Client JavaScript function to manipulate column data
– Example: format to all upper case
function allUpper(value) {
return value.toUpperCase();
}
Sorting
• Automatically attempts to provide ascending and descending
sorting on all columns
• Each sort only works if enabled in underlying view column
Preventing Sort Options
• Attach a function to the canSort property of the grid
– Receives column index number
• 1-based index
• Ascending sort is positive number, descending is negative
– Returns true or false
• Run code in onClientLoad event of page to attach function
– Example: Allow even-numbered columns to sort
dijit.byId('#{id:djxDataGrid1}').canSort = function(col){
if (col % 2 == 0) {
return true;
} else {
return false;
}
};
Opening Documents
• Link not built-in
• Row click events: onRowClick, onRowDblClick
– Client JavaScript
– Events receive an argument with many properties
• Code varies based on REST service type
REST Service Output
viewJsonService viewItemFileService
Open Doc - viewJsonService
var grid = arguments[0].grid;
var index = arguments[0].rowIndex;
var item = grid.getItem(index);
var unid = item[‘@unid’];
var url = ‘MyPageName.xsp?documentId=’ + unid +
‘&action=openDocument’;
window.document.location.href = url;
Open Doc - viewItemFileService
var index = arguments[0].rowIndex;
var unid =
REST_SERVICE._items[index].attributes[‘@unid’];
var url = ‘MyPageName.xsp?documentId=’ + unid +
‘&action=openDocument’;
window.document.location.href = url;
Search – Full Text
• Same steps as other display controls
1. Create search field and bind to scope variable
2. Set REST service’s search property to the scope variable
3. Add button that triggers partial refresh on grid and REST service
• Cannot sort results
• DB must be full-text indexed
Editable Columns
• Set column’s editable property to true
• Double-click cell to change to edit mode
• Save the changes – one line of client JavaScript
– REST_SERVICE_ID.save()
– Use the jsId property, if defined (otherwise id)
– ** Does not work without grid autoHeight set
• Undo changes – one line of client JavaScript (in theory)
– REST_SERVICE_ID.revert()
– Partial refresh on grid has same effect
Editable Columns – Field Types
• cellType property
– Cell (default) – plain text
– Select – drop-down list (compute options w/ SSJS)
– Bool – checkbox
– AlwaysEdit – not a field type
– RowIndex – has nothing to do with editing
Editable Columns – Field Types
• Combo Box
1. Include module: dojox.grid.cells.dijit
2. Set cell type: dojox.grid.cells.ComboBox
Editable Columns – Field Types
• Multi-line Edit box
1. Include module: dojox.grid.cells.dijit
2. Set cell type: dojox.grid.cells.Editor
Editable Columns – Field Types
• Date Picker
1. Include module: dojox.grid.cells.DateTextBox
2. Set cell type: dojox.grid.cells.DateTextBox
3. Only works in Notes 9
Editable Columns
• REST service’s save() function can accept callbacks
– Useful for displaying an error if save fails
var saveCallbacks = {onError: function()
{alert('There was an error saving your changes.');}
};
restServiceID.save(saveCallbacks);
• Editable Columns work with viewItemFileService services, but
require a Web Site document to allow put operations in order to
work with viewJsonService
• Can only edit columns mapped to a single field
• Grid has a singleClickEdit property
• Highlighting changes
HTML Columns
• Create custom column in REST service (or use existing view
column) with HTML content
• Add Grid Column to display HTML content column
• Set Grid property escapeHTMLInData = false
– Not good practice – vulnerable to XSS
Icon Columns
• Images don’t work as pass-thru HTML
• Requires column formatter function (client JS)
• Formatter can conditionally return <IMG> tag
• Does not require the escapeHTMLInData property
– Much more secure for all passthru HTML
Dojo EnhancedGrid
• Dojo module that extends DataGrid
• Already available on the server
• Provides enhanced features via plugins
• Check for available features based on Domino/Dojo version
– Domino 8.5.3 – Dojo 1.6
– Domino 9 – Dojo 1.8
– http://dojotoolkit.org/reference-
guide/1.6/dojox/grid/EnhancedGrid.html
Converting to EnhancedGrid
• Dojo Data Grid control creates a Dojo DataGrid
• Can modify to create a Dojo EnhancedGrid
1. Load the EnhancedGrid module
2. Set the grid Dojo type
3. Load required style sheets
Converting to EnhancedGrid
1. Load the EnhancedGrid module on the page
– Resources > Add > Dojo Module
– dojox.grid.EnhancedGrid
Converting to EnhancedGrid
2. Set grid Dojo type to dojox.grid.EnhancedGrid
– Properties > Dojo > Dojo type
Converting to EnhancedGrid
3. Load required style sheets
– Load relative to Domino server path
<xp:styleSheet
href="/.ibmxspres/dojoroot/dojox/grid/resources/Grid.css">
</xp:styleSheet>
<xp:styleSheet
href="/.ibmxspres/dojoroot/dojox/grid/resources/EnhancedGrid.css">
</xp:styleSheet>
Verify EnhancedGrid
EnhancedGrid Plugin - DnD
• Provides ability to drag and drop columns, rows, and cells
– Configuration object defines options
– Add a row selector in order to drag and drop rows
• Usage
1. Select content to drag
2. Release mouse button
3. Click on the data and drag
• IMPORTANT: When cells are moved, changes are automatically
saved
EnhancedGrid Plugin - DnD
1. Load the DnD plugin
– Properties > Resources > Add > Dojo Module
– dojox.grid.enhanced.plugins.DnD
EnhancedGrid Plugin - DnD
2. Add plugin to grid as an attribute
– Dojo > Add
• Name: plugins
• Value: {dnd: {dndConfig:{}}}
– All selection types enabled by default
EnhancedGrid Plugin - Filter
• Adds filter bar
• Up to 3 filtering rules
– Match all rules or any rule
– Select column to filter
– Select matching condition (is, contains, starts with, ends with…)
• No coding required!!
• Results are sortable
EnhancedGrid Plugin - Filter
1. Load the Filter plugin
– Properties > Resources > Add > Dojo Module
– dojox.grid.enhanced.plugins.Filter
EnhancedGrid Plugin - Filter
2. Add plugin to grid as an attribute
– Dojo > Add
• Name: plugins
• Value: {filter: true}
EnhancedGrid Plugin - Filter
3. Add a stylesheet
<xp:styleSheet
href="/.ibmxspres/dojoroot/dojox/grid/enhanced/resources/
claro/EnhancedGrid.css">
</xp:styleSheet>
EnhancedGrid – More Plugins
• Print
– Provides ability to preview or print grid contents
– Print/Preview “All”, Selected, Custom
• Exporter
– Provides grid data for export – you handle the rest
– Export “All”, Selected, Custom
• Menu
– Context menus for columns, rows, cells, selected
– Build with dijit menus/menu items
Dojo TreeGrid
• Provides multi-level categorization
• Can provide column totals and counts
• Extends Dojo DataGrid
– Cannot use EnhancedGrid plugins
• Poor documentation
• Apparently cannot use Dojo Data Grid control
TreeGrid - Implementation
• Programmatic – NOT the Dojo Data Grid control
1. Include required dojo modules and stylesheets
2. Set XPage property to parse dojo on load
3. Define a <div> to render the grid and set the size
4. Execute code onClientLoad to configure and generate the grid
5. Provide data for the grid (XAgent)
– Complicated format
...
{ id: 'AS', name:'Asia', type:'continent',
children:[{_reference:'CN'}, {_reference:'IN'}] },
{ id: 'CN', name:'China', type:'country' },
{ id: 'IN', name:'India', type:'country' },
...
TreeGrid – Totals and Counts
• Inline when collapsed, below when expanded
• Requires a different (but simpler) JSON model
{id:'AK', type: 'state', state:'AK', numPeople: 3,
childItems:[
{id:'B3093953178C98E905257838007ABC48', firstname:'Bella',
lastname: 'Martin', valueToAdd: 2},
{id:'7FDB9CCDE7D6923E05257838007ABC1E', firstname:'Brian',
lastname: 'Leggett', valueToAdd: 2}
] },
• Add an aggregate property
– Set to “sum” or “cnt”
– Numeric columns handled properly
– Text columns concatenated
– Formatter functions can modify the display (and hide text)
TreeGrid – Data Format Caveat
• Simpler JSON format causes blank rows when used without
counts/totals
TreeGrid - Features
• defaultOpen – expanded or collapsed
• openAtLevels – auto expand all categories with less items than
the defined amount
– Can accept an array for multiple levels of categorization
– Doesn’t work with ForestStoreModel
• expandoCell – column in which the expand/collapse icon displays
Questions?
• Data Grid Blog Series: http://xcellerant.net/dojo-grids-in-xpages
• Sample database coming to openNTF soon
• Twitter: @Balassaitis

More Related Content

What's hot

Msbi 2008 online training
Msbi 2008 online trainingMsbi 2008 online training
Msbi 2008 online training
ssmsbi
 
Oracle forms les07
Oracle forms  les07Oracle forms  les07
Oracle forms les07
Abed Othman
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11
Terry Yoast
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate Overview
Brett Meyer
 

What's hot (19)

Connect 2016-Move Your XPages Applications to the Fast Lane
Connect 2016-Move Your XPages Applications to the Fast LaneConnect 2016-Move Your XPages Applications to the Fast Lane
Connect 2016-Move Your XPages Applications to the Fast Lane
 
Big data for cio 2015
Big data for cio 2015Big data for cio 2015
Big data for cio 2015
 
Oracle 11g sql plsql training
Oracle 11g sql plsql trainingOracle 11g sql plsql training
Oracle 11g sql plsql training
 
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
 
Oracle dba 12c training syllabus
Oracle dba 12c training syllabusOracle dba 12c training syllabus
Oracle dba 12c training syllabus
 
Things Every Oracle DBA Needs to Know about the Hadoop Ecosystem
Things Every Oracle DBA Needs to Know about the Hadoop EcosystemThings Every Oracle DBA Needs to Know about the Hadoop Ecosystem
Things Every Oracle DBA Needs to Know about the Hadoop Ecosystem
 
Things Every Oracle DBA Needs To Know About The Hadoop Ecosystem
Things Every Oracle DBA Needs To Know About The Hadoop EcosystemThings Every Oracle DBA Needs To Know About The Hadoop Ecosystem
Things Every Oracle DBA Needs To Know About The Hadoop Ecosystem
 
How to Write Custom Modules for PHP-based E-Commerce Systems (2011)
How to Write Custom Modules for PHP-based E-Commerce Systems (2011)How to Write Custom Modules for PHP-based E-Commerce Systems (2011)
How to Write Custom Modules for PHP-based E-Commerce Systems (2011)
 
Msbi 2008 online training
Msbi 2008 online trainingMsbi 2008 online training
Msbi 2008 online training
 
Oracle developer Course in Jordan دورة اوراكل في الاردن
Oracle developer Course in Jordan دورة اوراكل في الاردنOracle developer Course in Jordan دورة اوراكل في الاردن
Oracle developer Course in Jordan دورة اوراكل في الاردن
 
Oracle forms les07
Oracle forms  les07Oracle forms  les07
Oracle forms les07
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11
 
Evolutionary database design
Evolutionary database designEvolutionary database design
Evolutionary database design
 
Java
JavaJava
Java
 
Netvu test slideshow
Netvu test slideshowNetvu test slideshow
Netvu test slideshow
 
Msbi 2012 online training
Msbi 2012 online trainingMsbi 2012 online training
Msbi 2012 online training
 
MIGRATION - PAIN OR GAIN?
MIGRATION - PAIN OR GAIN?MIGRATION - PAIN OR GAIN?
MIGRATION - PAIN OR GAIN?
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate Overview
 
oracle 10G DBA Training In Delhi NCR
oracle 10G DBA Training In Delhi NCRoracle 10G DBA Training In Delhi NCR
oracle 10G DBA Training In Delhi NCR
 

Similar to Living on the Grid - Unlock the Power of Dojo Data Grids in XPages - MWLUG 2013

ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14
Sisir Ghosh
 
Extjs3.4 Migration Notes
Extjs3.4 Migration NotesExtjs3.4 Migration Notes
Extjs3.4 Migration Notes
SimoAmi
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
Terry Yoast
 
DMann-SQLDeveloper4Reporting
DMann-SQLDeveloper4ReportingDMann-SQLDeveloper4Reporting
DMann-SQLDeveloper4Reporting
David Mann
 

Similar to Living on the Grid - Unlock the Power of Dojo Data Grids in XPages - MWLUG 2013 (20)

The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your ApplicationsThe Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
 
Dojo Grids in XPages
Dojo Grids in XPagesDojo Grids in XPages
Dojo Grids in XPages
 
Tech talk live share extras extension modules feb 13
Tech talk live   share extras extension modules feb 13Tech talk live   share extras extension modules feb 13
Tech talk live share extras extension modules feb 13
 
Presenting Data – An Alternative to the View Control
Presenting Data – An Alternative to the View ControlPresenting Data – An Alternative to the View Control
Presenting Data – An Alternative to the View Control
 
ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14
 
Extjs3.4 Migration Notes
Extjs3.4 Migration NotesExtjs3.4 Migration Notes
Extjs3.4 Migration Notes
 
Tech Talk Live on Share Extensibility
Tech Talk Live on Share ExtensibilityTech Talk Live on Share Extensibility
Tech Talk Live on Share Extensibility
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 
Asp.Net MVC 5 in Arabic
Asp.Net MVC 5 in ArabicAsp.Net MVC 5 in Arabic
Asp.Net MVC 5 in Arabic
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
 
Webcenter Sites Google Gadget Development Techniques
Webcenter Sites Google Gadget Development TechniquesWebcenter Sites Google Gadget Development Techniques
Webcenter Sites Google Gadget Development Techniques
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
CodeIgniter & MVC
CodeIgniter & MVCCodeIgniter & MVC
CodeIgniter & MVC
 
Dexterity in the Wild
Dexterity in the WildDexterity in the Wild
Dexterity in the Wild
 
Magento performance feat. core Hacks
Magento performance feat. core HacksMagento performance feat. core Hacks
Magento performance feat. core Hacks
 
tutorial2-notes2
tutorial2-notes2tutorial2-notes2
tutorial2-notes2
 
tutorial2-notes2
tutorial2-notes2tutorial2-notes2
tutorial2-notes2
 
DMann-SQLDeveloper4Reporting
DMann-SQLDeveloper4ReportingDMann-SQLDeveloper4Reporting
DMann-SQLDeveloper4Reporting
 
CUST-2 New Client Configuration & Extension Points in Share
CUST-2 New Client Configuration & Extension Points in ShareCUST-2 New Client Configuration & Extension Points in Share
CUST-2 New Client Configuration & Extension Points in Share
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 

Living on the Grid - Unlock the Power of Dojo Data Grids in XPages - MWLUG 2013

  • 1. MWLUG 2013 Living on the Grid – Unlock the Power of Dojo Data Grids (AD104) Brad Balassaitis, PSC Group
  • 2. Brad Balassaitis • Notes/Domino developer for 17 years, XPages 3+ years • Senior Consultant at PSC Group – XPages Developer – Project Lead • Contact Information – Blog: xcellerant.net – Twitter: @Balassaitis – LinkedIn: linkedin.com/in/bradbalassaitis
  • 3. Agenda • Dojo Data Grid Control – Creation and Default Features • Dojo Data Grid – Additional Features – Sorting, Opening Docs, Searching, Editing • Dojo EnhancedGrid – Conversion – Plugins • Dojo TreeGrid – Categorization – Counts and Totals
  • 4. Dojo Data Grid Control • Availability – Extension Library – 8.5.3 Upgrade Pack 1 – Notes 9 • Creates a Dojo DataGrid
  • 5. Why use the Dojo Data Grid? • It’s not a view panel • Feature-rich – Adjustable columns, storing, editing, and much more • Dojo is already on the Domino server • Enhanced plugins are available
  • 6. Creating a Dojo Data Grid 1. Create REST Service to provide data 2. Add the Dojo Data Grid control and bind to the REST service 3. Add Dojo Data Grid Columns
  • 7. REST Service • REST is a standard for client-server data exchange on the web • Common method for providing data to a grid • REST Service Control (ExtLib, 8.5.3 UP1, Notes9) – Data Access > REST Service
  • 8. REST Service - Creation 1. Add REST Service control to the page 2. Select the service type – basics > service > + > xe:viewJsonService 3. Set the contentType to application/json – basics > service > contentType 4. Select the view – basics > service > viewName 5. Set defaultColumns to true – basics > service > defaultColumns
  • 9. REST Service - Customization • Compute columns • System columns • Roll your own
  • 10. REST Service - Verification • Set pathInfo – All Properties > basics > pathInfo • Test it – Server.com/dbname.nsf/XPage.xsp/pathInfoName
  • 11. Creating a Dojo Data Grid 1. Create REST Service to provide data 2. Add the Dojo Data Grid control and bind to the REST service 3. Add Dojo Data Grid Columns
  • 12. Default Grid Features • Infinite scrolling • Adjustable column widths • Row highlighting • Extended selection mode • Sortable columns • Multiple row entries
  • 13. Additional Grid Properties • rowSelector • autoHeight • rowsPerPage • escapeHTMLInData • loadingMessage • errorMessage • dir
  • 14. Dojo Attributes • More grid features are available, but not via properties – e.g. Column Reordering, Grid Width • Dojo > Dojo attributes – or • All Properties > dojo > dojo attributes
  • 15. Column Reordering • Allows user to rearrange columns • Set via dojo attribute
  • 16. Column Reordering • Alternate method of setting attribute
  • 17. Grid Width • By default, takes up width of containers • autoWidth attribute sizes to the required width • Set via dojo attribute
  • 18. Grid Column Properties • label • width • hidden • editable • formatter – Client JavaScript function to manipulate column data – Example: format to all upper case function allUpper(value) { return value.toUpperCase(); }
  • 19. Sorting • Automatically attempts to provide ascending and descending sorting on all columns • Each sort only works if enabled in underlying view column
  • 20. Preventing Sort Options • Attach a function to the canSort property of the grid – Receives column index number • 1-based index • Ascending sort is positive number, descending is negative – Returns true or false • Run code in onClientLoad event of page to attach function – Example: Allow even-numbered columns to sort dijit.byId('#{id:djxDataGrid1}').canSort = function(col){ if (col % 2 == 0) { return true; } else { return false; } };
  • 21. Opening Documents • Link not built-in • Row click events: onRowClick, onRowDblClick – Client JavaScript – Events receive an argument with many properties • Code varies based on REST service type
  • 22. REST Service Output viewJsonService viewItemFileService
  • 23. Open Doc - viewJsonService var grid = arguments[0].grid; var index = arguments[0].rowIndex; var item = grid.getItem(index); var unid = item[‘@unid’]; var url = ‘MyPageName.xsp?documentId=’ + unid + ‘&action=openDocument’; window.document.location.href = url;
  • 24. Open Doc - viewItemFileService var index = arguments[0].rowIndex; var unid = REST_SERVICE._items[index].attributes[‘@unid’]; var url = ‘MyPageName.xsp?documentId=’ + unid + ‘&action=openDocument’; window.document.location.href = url;
  • 25. Search – Full Text • Same steps as other display controls 1. Create search field and bind to scope variable 2. Set REST service’s search property to the scope variable 3. Add button that triggers partial refresh on grid and REST service • Cannot sort results • DB must be full-text indexed
  • 26. Editable Columns • Set column’s editable property to true • Double-click cell to change to edit mode • Save the changes – one line of client JavaScript – REST_SERVICE_ID.save() – Use the jsId property, if defined (otherwise id) – ** Does not work without grid autoHeight set • Undo changes – one line of client JavaScript (in theory) – REST_SERVICE_ID.revert() – Partial refresh on grid has same effect
  • 27. Editable Columns – Field Types • cellType property – Cell (default) – plain text – Select – drop-down list (compute options w/ SSJS) – Bool – checkbox – AlwaysEdit – not a field type – RowIndex – has nothing to do with editing
  • 28. Editable Columns – Field Types • Combo Box 1. Include module: dojox.grid.cells.dijit 2. Set cell type: dojox.grid.cells.ComboBox
  • 29. Editable Columns – Field Types • Multi-line Edit box 1. Include module: dojox.grid.cells.dijit 2. Set cell type: dojox.grid.cells.Editor
  • 30. Editable Columns – Field Types • Date Picker 1. Include module: dojox.grid.cells.DateTextBox 2. Set cell type: dojox.grid.cells.DateTextBox 3. Only works in Notes 9
  • 31. Editable Columns • REST service’s save() function can accept callbacks – Useful for displaying an error if save fails var saveCallbacks = {onError: function() {alert('There was an error saving your changes.');} }; restServiceID.save(saveCallbacks); • Editable Columns work with viewItemFileService services, but require a Web Site document to allow put operations in order to work with viewJsonService • Can only edit columns mapped to a single field • Grid has a singleClickEdit property • Highlighting changes
  • 32. HTML Columns • Create custom column in REST service (or use existing view column) with HTML content • Add Grid Column to display HTML content column • Set Grid property escapeHTMLInData = false – Not good practice – vulnerable to XSS
  • 33. Icon Columns • Images don’t work as pass-thru HTML • Requires column formatter function (client JS) • Formatter can conditionally return <IMG> tag • Does not require the escapeHTMLInData property – Much more secure for all passthru HTML
  • 34. Dojo EnhancedGrid • Dojo module that extends DataGrid • Already available on the server • Provides enhanced features via plugins • Check for available features based on Domino/Dojo version – Domino 8.5.3 – Dojo 1.6 – Domino 9 – Dojo 1.8 – http://dojotoolkit.org/reference- guide/1.6/dojox/grid/EnhancedGrid.html
  • 35. Converting to EnhancedGrid • Dojo Data Grid control creates a Dojo DataGrid • Can modify to create a Dojo EnhancedGrid 1. Load the EnhancedGrid module 2. Set the grid Dojo type 3. Load required style sheets
  • 36. Converting to EnhancedGrid 1. Load the EnhancedGrid module on the page – Resources > Add > Dojo Module – dojox.grid.EnhancedGrid
  • 37. Converting to EnhancedGrid 2. Set grid Dojo type to dojox.grid.EnhancedGrid – Properties > Dojo > Dojo type
  • 38. Converting to EnhancedGrid 3. Load required style sheets – Load relative to Domino server path <xp:styleSheet href="/.ibmxspres/dojoroot/dojox/grid/resources/Grid.css"> </xp:styleSheet> <xp:styleSheet href="/.ibmxspres/dojoroot/dojox/grid/resources/EnhancedGrid.css"> </xp:styleSheet>
  • 40. EnhancedGrid Plugin - DnD • Provides ability to drag and drop columns, rows, and cells – Configuration object defines options – Add a row selector in order to drag and drop rows • Usage 1. Select content to drag 2. Release mouse button 3. Click on the data and drag • IMPORTANT: When cells are moved, changes are automatically saved
  • 41. EnhancedGrid Plugin - DnD 1. Load the DnD plugin – Properties > Resources > Add > Dojo Module – dojox.grid.enhanced.plugins.DnD
  • 42. EnhancedGrid Plugin - DnD 2. Add plugin to grid as an attribute – Dojo > Add • Name: plugins • Value: {dnd: {dndConfig:{}}} – All selection types enabled by default
  • 43. EnhancedGrid Plugin - Filter • Adds filter bar • Up to 3 filtering rules – Match all rules or any rule – Select column to filter – Select matching condition (is, contains, starts with, ends with…) • No coding required!! • Results are sortable
  • 44. EnhancedGrid Plugin - Filter 1. Load the Filter plugin – Properties > Resources > Add > Dojo Module – dojox.grid.enhanced.plugins.Filter
  • 45. EnhancedGrid Plugin - Filter 2. Add plugin to grid as an attribute – Dojo > Add • Name: plugins • Value: {filter: true}
  • 46. EnhancedGrid Plugin - Filter 3. Add a stylesheet <xp:styleSheet href="/.ibmxspres/dojoroot/dojox/grid/enhanced/resources/ claro/EnhancedGrid.css"> </xp:styleSheet>
  • 47. EnhancedGrid – More Plugins • Print – Provides ability to preview or print grid contents – Print/Preview “All”, Selected, Custom • Exporter – Provides grid data for export – you handle the rest – Export “All”, Selected, Custom • Menu – Context menus for columns, rows, cells, selected – Build with dijit menus/menu items
  • 48. Dojo TreeGrid • Provides multi-level categorization • Can provide column totals and counts • Extends Dojo DataGrid – Cannot use EnhancedGrid plugins • Poor documentation • Apparently cannot use Dojo Data Grid control
  • 49. TreeGrid - Implementation • Programmatic – NOT the Dojo Data Grid control 1. Include required dojo modules and stylesheets 2. Set XPage property to parse dojo on load 3. Define a <div> to render the grid and set the size 4. Execute code onClientLoad to configure and generate the grid 5. Provide data for the grid (XAgent) – Complicated format ... { id: 'AS', name:'Asia', type:'continent', children:[{_reference:'CN'}, {_reference:'IN'}] }, { id: 'CN', name:'China', type:'country' }, { id: 'IN', name:'India', type:'country' }, ...
  • 50. TreeGrid – Totals and Counts • Inline when collapsed, below when expanded • Requires a different (but simpler) JSON model {id:'AK', type: 'state', state:'AK', numPeople: 3, childItems:[ {id:'B3093953178C98E905257838007ABC48', firstname:'Bella', lastname: 'Martin', valueToAdd: 2}, {id:'7FDB9CCDE7D6923E05257838007ABC1E', firstname:'Brian', lastname: 'Leggett', valueToAdd: 2} ] }, • Add an aggregate property – Set to “sum” or “cnt” – Numeric columns handled properly – Text columns concatenated – Formatter functions can modify the display (and hide text)
  • 51. TreeGrid – Data Format Caveat • Simpler JSON format causes blank rows when used without counts/totals
  • 52. TreeGrid - Features • defaultOpen – expanded or collapsed • openAtLevels – auto expand all categories with less items than the defined amount – Can accept an array for multiple levels of categorization – Doesn’t work with ForestStoreModel • expandoCell – column in which the expand/collapse icon displays
  • 53. Questions? • Data Grid Blog Series: http://xcellerant.net/dojo-grids-in-xpages • Sample database coming to openNTF soon • Twitter: @Balassaitis