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

[Bug] Controlled selected prop doesn't work with string or number value #44

Closed
mijikim opened this issue Feb 12, 2021 · 2 comments
Closed

Comments

@mijikim
Copy link

mijikim commented Feb 12, 2021

When a string or number is passed in as selected, the grid does not select the appropriate row. This works if an object with same value is passed in.

We are using @inovua/reactdatagrid-enterprise and it's v4.0.23.

Reproduction

Below code is a modification of code sample on https://reactdatagrid.io/docs/api-reference#props-selected

import React, { useState, useCallback } from 'react'
import ReactDataGrid from '@inovua/reactdatagrid-enterprise'
import '@inovua/reactdatagrid-enterprise/index.css'

import people from './people'
import flags from './flags'

const gridStyle = { minHeight: 550 }

const columns = [
  { name: 'id', defaultWidth: 60, header: 'Id', defaultVisible: false },
  { name: 'name', defaultFlex: 1, header: 'Name' },
  { name: 'country', defaultFlex: 1, header: 'Country',
    render: ({ value }) => flags[value] ? flags[value] : value
  },
  { name: 'age', type: 'number', defaultFlex: 1, header: 'Age' },
  { name: 'email', header: 'Email', defaultFlex: 1 }
]

const App = () => {
  return (
    <div>
      <ReactDataGrid
        idProperty="id"
        multiSelect
        // below will work if passed in { 1: true }
        // also does not work when passed in '1'
        selected={1}
        style={gridStyle}
        columns={columns}
        dataSource={people}
      />
    </div>
  );
}

export default () => <App />
@inovua-admin
Copy link
Contributor

This is expected behaviour - please read the docs at https://reactdatagrid.io/docs/api-reference#props-selected

If you want multi-select, (you have specified multiSelect=true in the example above), you have to pass an object. If you use single selection, you can pass a string or number.

@inovua-admin
Copy link
Contributor

inovua-admin commented Feb 15, 2021

In multi-selection, the keys of the object represent the ids of the rows being selected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants