Add itemTree render cell option (#3342)

This commit is contained in:
windingwind 2023-08-30 12:11:25 +08:00 committed by GitHub
parent b72894d874
commit 794e89d307
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 3 deletions

View file

@ -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) + '.');

View file

@ -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
*/

View file

@ -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