Introduced in v11.0.0, Rich Objects are plain objects used to define the behavior of rich content in cells—
such as hyperlinks, images or rich media—throughout their lifecycle in PQGrid at a single place.
Rich Objects support the following key operations:
Rich Objects are defined in the namespace pq.RichObjs. There are 2 inbuilt
objects: pq.RichObjs.Link and pq.RichObjs.Pic
pq.RichObjs.rowData.pq_cellprop[ dataIndx ]
A Rich object extends pq.RichObj and provides concrete implementations for these methods or properties
to handle specific types of operations of a cell in PQGrid.
render: Defines how the rich cell content is displayed, takes in same arguments and returns same value
as column.render callback.
/**
* @method render
* @returns {string|Object} - Returns a plain string, HTML string or an object
specifying styles, attributes, or classes.
*/
render( ui ) {}
editor: Defines a custom editor, it uses and returns same properties as the
column.editor in pqgrid.
/**
* @property editor ( optional )
* @type {Object} - object specifying type of editor, initialization function, etc
*/
editor = {
type: '...',
init: function( ui ){}
}
getEditorVal: Extracts the Rich Object (RO) cell data from the custom editor in a standardized format.
/**
* @method getEditorVal (optional)
* @param {Node} editor - The root container of the custom editor.
* @returns {Object}
*/
getEditorVal(editor) {
return {
// Primitive value such as string, number, or boolean
//stored in rowData[ dataIndx ]
val: ...,
// Additional data for the RO instance, passed as key-value pairs
//stored in rowData.pq_cellprop[ dataIndx ]
prop: { ... }
};
}
compareKeys: Name of properties which are used for comparison between cut and pasted cells.
/**
* @property compareKeys
* @type {Array} - Name of properties which are compared while cut paste of cells.
*/
static compareKeys = []
toExport: Prepares the cell content for export in different formats. This method can be either synchrnous or asynchronous. All the exported data is added to the cell object.
/**
* @method toExport (optional)
* @param {Object} cell - cell to be exported as js workbook, or js object ( for other formats )
* @param {string} format - The target export format (e.g., 'wb', 'pdf', 'csv', 'htm', 'js', etc ).
*/
async toExport(cell, format) {}
toHtml: Converts the class data into an HTML format for clipboard operations.
This method can be either synchrnous or asynchronous.
toString is used if this method is not implemented.
/**
* @method toHtml (optional)
* @returns {string} - Returns an HTML string
*/
async toHtml() {}
toString: Defines string representation of the cell’s value, also used for clipboard operation if toHtml is not implemented.
/**
* @method toString
* @returns {string} - Returns string
*/
toString() {}
toImport: Converts imported cell from js workbook into a new instance of RenderCell.
/**
* @method toImport ( optional)
* @param {Object} cell - The imported cell from a js workbook.
* @returns {RenderCell} - Returns a new Render Object populated from imported value.
*/
toImport( cell ) {}
toObject: Parses clipboard data cooresponding to a cell into a RenderCell instance.
/**
* @method toObject (static, optional)
* @description
* @param {string} val - cell data extracted from pasted clipboard data.
* @returns {RenderCell|undefined} - Returns a new instance if conversion is successful, otherwise undefined.
*/
static toObject(val) {}
After defining a Rich Object, it can be published for
all grids by adding it to pq.RichObjs object
Rich objects can be used or added in grid cells in 2 ways:
rowData.pq_cellprop[ dataIndx ] of grid data
data[0][4] = 'Content/pics/cube.gif'
data[0].pq_cellprop = {
4: {
inst: 'Pic',
width: 100
}
}
or add via grid.updateRow or grid.addRow method
grid1.updateRow({
newRow: {
1: {
val: 'ParamQuery API',
style: {
background: "#ff9999"
},
prop: {
inst: 'Link', //Rich object
link: '../api'
}
}
},
rowIndx: 1
})
Note: The prop.inst property marks a cell as a Rich Object.
The value of prop.inst is used as a key to look up the corresponding
definition in pq.RichObjs[name]. This allows the grid to associate
the cell with a predefined rich object type and render it accordingly.