Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First column is blank in v5 when indexing into jagged arrays rather than arrays of objects #1343

Closed
3 of 11 tasks
mungojam opened this issue Oct 28, 2018 · 4 comments
Closed
3 of 11 tasks
Labels

Comments

@mungojam
Copy link
Contributor

Which version of React JS are you using?

✅ Officially supported ✅

  • v15.4.x

⚠️ Not officially supported, expect warnings ⚠️

  • v15.5.x
  • v15.6.x

☣️ Not officially supported, expect warnings and errors ☣️

  • v16.x.x

Which browser are you using?

✅ Officially supported ✅

  • IE 9 / IE 10 / IE 11
  • Edge
  • Chrome

⚠️ Not officially supported, but "should work" ⚠️

  • Firefox
  • Safari

I'm submitting a ...

  • 🐛 Bug Report
  • 💡 Feature Request

👋 Need general support? Not sure about how to use React itself, or how to get started with the Grid?
Please do not submit support request here. Instead see

https://github.com/adazzle/react-data-grid/blob/master/CONTRIBUTING.md


Issue Details

When using v4, I was able to have my backing data stored as a jagged/nested array, with the outer dimension for the rows and the inner dimension for the columns. I then used the column index as the key for each column. This made it easy to work with data coming as an array of column headings plus an array of arrays with the data in.

With v5 however, the first column is coming out blank:

image

Here's the MRE:

import React from 'react';

import ReactDataGrid from 'react-data-grid';

export default () => {
  const rows = [];
  for (let i = 1; i < 20; i++) {
    rows.push([i, 'Title ' + i, i * 20]
    );
  }

  const columns = [
    { key: 0, name: 'ID' },
    { key: 1, name: 'Title' },
    { key: 2, name: 'Count' } ];

  return (
    <div className="App">
      <ReactDataGrid
        columns={columns}
        rowGetter={i => rows[i]}
        rowsCount={rows.length}
        minHeight={500} />
    </div>
  );
}
@mungojam
Copy link
Contributor Author

mungojam commented Oct 28, 2018

When I switch around the keys, it's evident that it is actually a key of 0 is the problem:

  const columns = [
    { key: 1, name: 'ID' },
    { key: 0, name: 'Title' },
    { key: 2, name: 'Count' } ];

image

@mungojam
Copy link
Contributor Author

It all seems to revolve around this line:

value: this.getCellValue(key || i),

0 || something results in something, not 0. And so it turns out that in v4 this was falling back on i, which happened to be just what I wanted. I could have taken out the keys altogether.

In v5 however, i is undefined for some reason. So I guess there are maybe two issues here, treatment of 0 and lack of i. I'll try and dig into why i is undefined

@mungojam mungojam mentioned this issue Oct 28, 2018
10 tasks
mungojam added a commit to mungojam/react-data-grid that referenced this issue Oct 28, 2018
malonecj pushed a commit that referenced this issue Nov 13, 2018
@stale
Copy link

stale bot commented Nov 27, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please reopen this if you feel it has been incorrectly closed and we will do our best to look into it. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 27, 2018
@mungojam
Copy link
Contributor Author

mungojam commented Dec 1, 2018

There's still a remaining bug for any column key of 0 if it isn't the first column, but that will be a pretty rare scenario and the main issue is fixed

@mungojam mungojam closed this as completed Dec 1, 2018
rossjp pushed a commit to rossjp/react-data-grid that referenced this issue Dec 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant