eLabSDK2.Inventory.Sample.SampleList

Hierarchy

Methods

getSelectedSamples

Static getSelectedSamples(): SampleListItem[]

Get the sample objects the user has selected, with series expanded into their members.

Reads the surface your action was invoked from. How much of each sample you get depends
on that surface: the inventory sample list returns the full object, while an ELN
experiment sample section returns only what it loads — no barcode, meta or
quantity. Returns an empty array if nothing is selected.

Returns

SampleListItem[]

The selected samples. Every surface supplies sampleID, name, type and checkedOut, plus series.seriesID on series members. Anything beyond that depends on the surface.

Example

// Filter selected samples by type
const selected = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamples();
const antibodies = selected.filter(s => s.sampleTypeID === 5);
const reagents = selected.filter(s => s.sampleTypeID === 10);
console.log(`Antibodies: ${antibodies.length}, Reagents: ${reagents.length}`);

Example

// Export selected samples with full details
const selected = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamples();
const exportData = selected.map(sample => ({
  id: sample.sampleID,
  name: sample.name,
  barcode: sample.barcode,
  location: sample.storageLayerName,
  type: sample.sampleTypeName
}));
downloadCSV(exportData, 'selected-samples.csv');

Example

// Perform operations on selected samples
const selected = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamples();
for (const sample of selected) {
  if (sample.quantity && sample.quantity.amount < sample.quantity.thresholdAmount) {
    console.log(`Warning: ${sample.name} is below threshold`);
  }
}

getSelectedSamplesIDs

Static getSelectedSamplesIDs(): number[]

Get the IDs of the samples the user has selected.

Reads the surface your action was invoked from — the inventory sample list, or an ELN
experiment sample section. Prefer this over getSelectedSamples() when you only need
IDs. Returns an empty array if nothing is selected.

Returns

number[]

An array of numeric sample IDs for all currently selected samples.

Example

// Get selected sample IDs and log count
const selectedIds = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs();
console.log(`${selectedIds.length} samples selected`);
console.log('Sample IDs:', selectedIds);

Example

// Use IDs for bulk API call
const sampleIds = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs();
if (sampleIds.length > 0) {
  await api.updateSamples(sampleIds, { status: 'ARCHIVED' });
  eLabSDK2.UI.Toast.showToast(`${sampleIds.length} samples archived`, 3000);
}

Example

// Check selection before performing action
const selectedIds = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs();
if (selectedIds.length === 0) {
  eLabSDK2.UI.Toast.showToast('Please select at least one sample');
  return;
}
performBulkOperation(selectedIds);

onAfterPageLoad

Static onAfterPageLoad(callback, id): void

Register a callback to execute after the sample list page DOM has been fully rendered.

This event fires after the page has completed rendering the DOM and all initial sample
data is loaded and displayed. Use this for tasks that require the DOM to exist, such as
manipulating page elements, attaching event listeners, initializing UI components, or
performing actions based on the loaded sample data.

Parameters

NameTypeDescription
callbackFunctionFunction to execute after the DOM is rendered. Receives detail information as parameter.
idstringUnique identifier for this callback registration.

Returns

void

Example

// Manipulate DOM after page loads
eLabSDK2.Inventory.Sample.SampleList.onAfterPageLoad((detail) => {
  console.log('Sample list rendered:', detail);
  // Add custom styling or elements
  const listContainer = document.querySelector('.sample-list');
  if (listContainer) {
    listContainer.classList.add('custom-theme');
  }
}, 'customize-ui');

Example

// Attach event listeners after render
eLabSDK2.Inventory.Sample.SampleList.onAfterPageLoad(() => {
  document.querySelectorAll('.sample-row').forEach(row => {
    row.addEventListener('dblclick', handleSampleDoubleClick);
  });
}, 'attach-event-listeners');

Example

// Initialize third-party components
eLabSDK2.Inventory.Sample.SampleList.onAfterPageLoad(() => {
  // Initialize DataTables, tooltips, or other UI libraries
  $('.sample-tooltip').tooltip();
  initializeCustomFilters();
}, 'init-ui-components');

Example

// Measure page load time
eLabSDK2.Inventory.Sample.SampleList.onAfterPageLoad(() => {
  const loadTime = Date.now() - window.sampleListLoadStart;
  console.log(`Sample list loaded in ${loadTime}ms`);
  trackAnalytics('sample_list_load_time', loadTime);
}, 'measure-performance');

Overrides

Sample.onAfterPageLoad


onBeforePageLoad

Static onBeforePageLoad(callback, id): void

Register a callback to execute before the sample list page loads data and renders the DOM.

This event fires at the very beginning of the page load process, before any sample data
is fetched or the DOM is rendered. Use this for early initialization tasks such as
setting up global state, preparing data structures, modifying filters, or configuring
the page loading behavior. This is the earliest hook available in the sample list
page lifecycle.

Parameters

NameTypeDescription
callbackFunctionFunction to execute before page load begins. Receives detail information as parameter.
idstringUnique identifier for this callback registration.

Returns

void

Example

// Initialize custom state before page loads
eLabSDK2.Inventory.Sample.SampleList.onBeforePageLoad((detail) => {
  console.log('Sample list loading:', detail);
  initializeCustomFilters();
  setupAnalyticsTracking();
}, 'init-sample-list');

Example

// Modify filters before data loads
eLabSDK2.Inventory.Sample.SampleList.onBeforePageLoad(() => {
  // Apply custom default filters
  const userRole = getUserRole();
  if (userRole === 'restricted') {
    applyRestrictedFilters();
  }
}, 'apply-custom-filters');

Example

// Track page load performance
eLabSDK2.Inventory.Sample.SampleList.onBeforePageLoad(() => {
  window.sampleListLoadStart = Date.now();
}, 'performance-tracking');

Overrides

Sample.onBeforePageLoad


registerAction

Static registerAction(action): void

Register a custom bulk action button for sample lists.

The button appears whenever one or more samples are selected, on every surface that lists
samples: the inventory sample list, the storage-layer and equipment sample lists, the
series-detail Samples tab and ELN experiment sample sections. Use bulk actions to act on
many samples at once — exporting, moving, changing status, or your own workflow.

ELN sections run add-ons sandboxed, so there every SDK call returns a Promise and page
globals are out of reach. Await every SDK call and use nothing outside the SDK, so the same
action works on every surface.

While the action runs, getSelectedSamplesIDs(), getSelectedSamples() and
reloadSamples() all read the surface the user invoked it from.

Note: read the selection at the very start of your onClick, before anything else.
If another action starts elsewhere on the page while yours is waiting, yours will read
that other section's selection instead.

Parameters

NameTypeDescription
actionAction{id: string, label: string, title?: string, icon?: string, onClick: () => void, isVisible?: (() => boolean) | boolean}

Returns

void

Example

// Add bulk export action for selected samples
eLabSDK2.Inventory.Sample.SampleList.registerAction({
  id: 'bulk-export-samples',
  label: 'Export to CSV',
  title: 'Export selected samples to CSV',
  icon: 'fas fa-file-csv',
  onClick: () => {
    const selected = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamples();
    const csvData = convertSamplesToCSV(selected);
    downloadFile(csvData, 'samples.csv');
  }
});

Example

// Every SDK call is awaited, because in an ELN section the add-on is sandboxed and each
// one returns a Promise.
eLabSDK2.Inventory.Sample.SampleList.registerAction({
  id: 'mark-as-consumed',
  label: 'Mark as Consumed',
  icon: 'fas fa-check',
  onClick: async () => {
    const sampleIds = await eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs();
    await updateSampleStatus(sampleIds, 'CONSUMED');
    await eLabSDK2.Inventory.Sample.SampleList.reloadSamples();
    await eLabSDK2.UI.Toast.showToast('Samples marked as consumed', 3000);
  }
});

registerAddSampleAction

Static registerAddSampleAction(action): void

Register a custom action in the 'Add Sample' workflow.

This adds a custom action that appears in the sample creation workflow, allowing you
to extend or customize the sample creation process. Use this to add validation,
trigger additional workflows, or integrate custom functionality when samples are created.

Parameters

NameTypeDescription
actionAction{id: string, label: string, onClick: (sampleData: any) => void | boolean}

Returns

void

Example

// Add validation action during sample creation
eLabSDK2.Inventory.Sample.SampleList.registerAddSampleAction({
  id: 'validate-sample-barcode',
  label: 'Validate Barcode',
  onClick: (sampleData) => {
    const isValid = validateBarcode(sampleData.barcode);
    if (!isValid) {
      eLabSDK2.UI.Toast.showToast('Invalid barcode format', 5000);
      return false;
    }
    return true;
  }
});

Example

// Trigger external system integration
eLabSDK2.Inventory.Sample.SampleList.registerAddSampleAction({
  id: 'sync-to-external-system',
  label: 'Sync to LIMS',
  onClick: async (sampleData) => {
    await syncToExternalLIMS(sampleData);
    eLabSDK2.UI.Toast.showToast('Sample synced to LIMS', 3000);
  }
});

reloadSamples

Static reloadSamples(): void

Re-fetch the samples from the server.

Refreshes the surface your action was invoked from, keeping its current filters, and
clears the selection. Call it after your action creates, updates or deletes samples so
the user sees the result.

Returns

void

Example

// Reload after creating a new sample
async function createSample(sampleData) {
  await api.createSample(sampleData);
  eLabSDK2.Inventory.Sample.SampleList.reloadSamples();
  eLabSDK2.UI.Toast.showToast('Sample created successfully', 3000);
}

Example

// Reload after bulk update
async function updateSelectedSamples(updates) {
  const sampleIds = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs();
  await api.updateSamples(sampleIds, updates);
  eLabSDK2.Inventory.Sample.SampleList.reloadSamples();
}

Example

// Reload in a custom bulk action
eLabSDK2.Inventory.Sample.SampleList.registerAction({
  id: 'archive-samples',
  label: 'Archive',
  onClick: async () => {
    const sampleIds = eLabSDK2.Inventory.Sample.SampleList.getSelectedSamplesIDs();
    await archiveSamples(sampleIds);
    eLabSDK2.Inventory.Sample.SampleList.reloadSamples();
    eLabSDK2.UI.Toast.showToast('Samples archived', 3000);
  }
});

© 2026 eLabNext


Did this page help you?