Untitled

mail@pastecode.io avatar
unknown
plain_text
11 days ago
849 B
0
Indexable
Never
function extractColumnsFromTable(className, columnIndexes) {
  const table = document.querySelector(`.${className}`);
  if (!table) {
    console.error(`Table with class name ${className} not found.`);
    return;
  }

  const rows = table.querySelectorAll('tr');
  const extractedData = [];

  rows.forEach(row => {
    const cells = row.querySelectorAll('td, th');
    const rowData = [];
    columnIndexes.forEach(index => {
      if (index < cells.length) {
        rowData.push(cells[index].textContent.trim());
      }
    });
    if (rowData.length > 0) {
      extractedData.push(rowData);
    }
  });

  return extractedData;
}

// Example usage:
const columnsToExtract = [4, 6, 7]; // Note: column indexes are zero-based
const data = extractColumnsFromTable('kbn-table', columnsToExtract);
console.log(data);
Leave a Comment