Skip to content

Objects

Zotero : object

Typedefs

ItemTreeColumnDataProviderstring
ItemTreeColumnRenderCellHTMLElement

Zotero : object

Kind: global namespace

Zotero.ItemTreeManager

Manages item tree APIs.

Kind: static property of Zotero

ItemTreeManager.registerColumn(option) ⇒ string | false

Register a custom column, must be valid with a unique dataKey.

Note that the dataKey you use here may be different from the one returned by the function. This is because the dataKey is prefixed with the pluginID to avoid conflicts after the column is registered.

Kind: static method of ItemTreeManager
Returns: string | false - - The dataKey of the added column or false if no column is added

ParamTypeDefaultDescription
optionObjectAn option or array of options to register
option.dataKeystringRequired, see use in ItemTree#_getRowData()
option.labelstringThe column label. Either a string or the id to an i18n string.
option.pluginIDstringSet plugin ID to auto remove column when plugin is removed.
[option.enabledTreeIDs]Array.<string>[]Which tree ids the column should be enabled in. If undefined, enabled in main tree. If ["*"], enabled in all trees.
[option.defaultIn]Array.<string>Will be deprecated. Types of trees the column is default in. Can be [default, feed];
[option.disabledIn]Array.<string>Will be deprecated. Types of trees where the column is not available
[option.sortReverse]booleanfalseDefault: false. Set to true to reverse the sort order
[option.flex]number1Default: 1. When the column is added to the tree how much space it should occupy as a flex ratio
[option.width]stringA column width instead of flex ratio. See above.
[option.fixedWidth]booleanDefault: false. Set to true to disable column resizing
[option.staticWidth]booleanDefault: false. Set to true to prevent columns from changing width when the width of the tree increases or decreases
[option.noPadding]booleanSet to true for columns with padding disabled in stylesheet
[option.minWidth]numberOverride the default [20px] column min-width for resizing
[option.iconLabel]React.ComponentSet an Icon label instead of a text-based one
[option.iconPath]stringSet an Icon path, overrides
[option.htmlLabel]string | React.ComponentSet an HTML label, overrides {iconLabel} and {label}. Can be a HTML string or a React component.
[option.showInColumnPicker]booleantrueDefault: true. Set to true to show in column picker.
[option.columnPickerSubMenu]booleanfalseDefault: false. Set to true to display the column in "More Columns" submenu of column picker.
[option.primary]booleanShould only be one column at the time. Title is the primary column
[option.dataProvider]ItemTreeColumnDataProviderCustom data provider that is called when rendering cells
[option.renderCell]ItemTreeColumnRenderCellThe cell renderer function
[option.zoteroPersist]Array.<string>Which column properties should be persisted between zotero close

Example
A minimal custom column:

javascript
// You can unregister the column later with Zotero.ItemTreeManager.unregisterColumn(registeredDataKey);
const registeredDataKey = Zotero.ItemTreeManager.registerColumn({
  dataKey: "rtitle",
  label: "Reversed Title",
  pluginID: "my-plugin@my-namespace.com", // Replace with your plugin ID
  dataProvider: (item, dataKey) => {
    return item.getField("title").split("").reverse().join("");
  },
});

Example
A custom column using all available options. Note that the column will only be shown in the main item tree.

javascript
const registeredDataKey = Zotero.ItemTreeManager.registerColumn({
  dataKey: "rtitle",
  label: "Reversed Title",
  enabledTreeIDs: ["main"], // only show in the main item tree
  sortReverse: true, // sort by increasing order
  flex: 0, // don't take up all available space
  width: 100, // assign fixed width in pixels
  fixedWidth: true, // don't allow user to resize
  staticWidth: true, // don't allow column to be resized when the tree is resized
  minWidth: 50, // minimum width in pixels
  iconPath: "chrome://zotero/skin/tick.png", // icon to show in the column header
  htmlLabel: '<span style="color: red;">reversed title</span>', // use HTML in the label. This will override the label and iconPath property
  showInColumnPicker: true, // show in the column picker
  columnPickerSubMenu: true, // show in the column picker submenu
  pluginID: "my-plugin@my-namespace.com", // plugin ID
  dataProvider: (item, dataKey) => {
    // item: the current item in the row
    // dataKey: the dataKey of the column
    // return: the data to display in the column
    return item.getField("title").split("").reverse().join("");
  },
  renderCell: (index, data, column, isFirstColumn, doc) => {
    // index: the index of the row
    // data: the data to display in the column, return of `dataProvider`
    // column: the column options
    // isFirstColumn: true if this is the first column
    // doc: the document of the item tree
    // return: the HTML to display in the cell
    const cell = doc.createElement("span");
    cell.className = `cell ${column.className}`;
    cell.textContent = data;
    cell.style.color = "red";
    return cell;
  },
  zoteroPersist: ["width", "hidden", "sortDirection"], // persist the column properties
});

ItemTreeManager.registerColumns()

Deprecated

Kind: static method of ItemTreeManager

ItemTreeManager.unregisterColumn(dataKey) ⇒ boolean

Unregister a custom column.

Kind: static method of ItemTreeManager
Returns: boolean - - true if the column was unregistered, false if the column was not found

ParamTypeDescription
dataKeystringThe dataKey of the column to unregister

ItemTreeManager.unregisterColumns()

Deprecated

Kind: static method of ItemTreeManager

ItemTreeManager.refreshColumns() ⇒ void

Refresh the columns in the item tree

Kind: static method of ItemTreeManager

ItemTreeColumnDataProvider ⇒ string

Kind: global typedef
Returns: string - - The data to display in the column

ParamTypeDescription
itemZotero.ItemThe item to get data from
dataKeystringThe dataKey of the column

ItemTreeColumnRenderCell ⇒ HTMLElement

Kind: global typedef
Returns: HTMLElement - - The HTML to display in the cell

ParamTypeDescription
indexnumberThe index of the row
datastringThe data to display in the column
columnItemTreeColumnOptions | ObjectThe column options
isFirstColumnbooleantrue if this is the first column
docDocumentThe document of the item tree