diff --git a/chrome/content/zotero/itemTree.jsx b/chrome/content/zotero/itemTree.jsx index 1bf7f8fc81..976c83cb22 100644 --- a/chrome/content/zotero/itemTree.jsx +++ b/chrome/content/zotero/itemTree.jsx @@ -2829,6 +2829,14 @@ var ItemTree = class ItemTree extends LibraryTree { else if (column.dataKey === 'hasAttachment') { return this._renderHasAttachmentCell(index, data, column); } + else if (column.renderCell) { + try { + return column.renderCell.apply(this, arguments); + } + catch (e) { + Zotero.logError(e); + } + } let cell = renderCell.apply(this, arguments); if (column.dataKey === 'numNotes' && data) { cell.setAttribute('aria-label', Zotero.getString('pane.item.notes.count', data, data) + '.'); diff --git a/chrome/content/zotero/itemTreeColumns.jsx b/chrome/content/zotero/itemTreeColumns.jsx index 08fcd2be55..ba25445d1c 100644 --- a/chrome/content/zotero/itemTreeColumns.jsx +++ b/chrome/content/zotero/itemTreeColumns.jsx @@ -49,6 +49,7 @@ const Icons = require('components/icons'); * @property {boolean} [primary] - Should only be one column at the time. Title is the primary column * @property {boolean} [custom] - Set automatically to true when the column is added by the user * @property {(item: Zotero.Item, dataKey: string) => string} [dataProvider] - Custom data provider that is called when rendering cells + * @property {(index: number, data: string, column: ItemTreeColumnOptions & {className: string}) => HTMLElement} renderCell - The cell renderer function * @property {string[]} [zoteroPersist] - Which column properties should be persisted between zotero close */ diff --git a/chrome/content/zotero/xpcom/itemTreeManager.js b/chrome/content/zotero/xpcom/itemTreeManager.js index ce38f8c48a..2753af3643 100644 --- a/chrome/content/zotero/xpcom/itemTreeManager.js +++ b/chrome/content/zotero/xpcom/itemTreeManager.js @@ -1,7 +1,7 @@ /* ***** BEGIN LICENSE BLOCK ***** - Copyright © 2019 Corporation for Digital Scholarship + Copyright © 2023 Corporation for Digital Scholarship Vienna, Virginia, USA https://digitalscholar.org @@ -88,6 +88,17 @@ class ItemTreeManager { * // return: the data to display in the column * return item.getField('title').split('').reverse().join(''); * }, + * renderCell: (index, data, column) => { + * // index: the index of the row + * // data: the data to display in the column, return of `dataProvider` + * // column: the column options + * // return: the HTML to display in the cell + * const cell = document.createElement('span'); + * cell.className = `cell ${column.className}`; + * cell.textContent = data; + * cell.style.color = 'red'; + * return cell; + * }, * zoteroPersist: ['width', 'hidden', 'sortDirection'], // persist the column properties * }); * ``` @@ -132,6 +143,7 @@ class ItemTreeManager { * @param {string | string[]} dataKeys - The dataKey of the column to unregister * @returns {boolean} true if the column(s) are unregistered * @example + * The `registeredDataKey` is returned by the `registerColumns` function. * ```js * Zotero.ItemTreeManager.unregisterColumns(registeredDataKey); * ``` @@ -145,8 +157,6 @@ class ItemTreeManager { return true; } - // TODO: add cell renderer registration - /** * Get column(s) that matches the properties of option * @param {string | string[]} [filterTreeIDs] - The tree IDs to match