Coder Social home page Coder Social logo

Comments (4)

fotoflo avatar fotoflo commented on July 26, 2024 1

Hi, first off, im so rude... I must thank you for making this awesome library... really helpful!

Here's how im making sure i can get all the headers (for use with react-table)

import { ROWS_TO_GLEAN_HEADERS_FROM } from "next.config";
    // moved the const to config to make it easier to remember there's a bug laying in wait

// go through the dataset and make sure we have all the row headers
export const getItemsHeaders = (tableData) => {
  if (typeof tableData === "undefined") return;

  const headerSet = new Set(); // Collapse a Set to get the unique items
  tableData.some((cell, index) => {
    // just go through the first n rows
    if (index > ROWS_TO_GLEAN_HEADERS_FROM) return; // NOTE: optimization which could cause a bug if the included rows do not contain all the headers
    Object.keys(cell).forEach((key) => headerSet.add(key));
  });

  const headers = Array.from(headerSet); // collapse the set

  return headers.map((header) => {
    return {
      Header: header.toUpperCase(),
      accessor: header,
    };
  });
};

from use-google-sheets.

gglukmann avatar gglukmann commented on July 26, 2024

Can you make the PR to https://github.com/gglukmann/google-sheets-mapper?

from use-google-sheets.

gglukmann avatar gglukmann commented on July 26, 2024

What would like to have as header? Index of row?

from use-google-sheets.

fotoflo avatar fotoflo commented on July 26, 2024

Hi just seeing this.
Row zero would be the first row... usually that makes the table head. I solved the issue a while ago but, if i recall, if there's a blank cell in the sheet, it would create offset on that row? So we ahve to reduce to get all of the keys in the whole sheet to make the headers.

from use-google-sheets.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.