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

Enhancement. Important for my data use case. #17

Closed
johnpittman opened this issue Jul 16, 2019 · 5 comments
Closed

Enhancement. Important for my data use case. #17

johnpittman opened this issue Jul 16, 2019 · 5 comments

Comments

@johnpittman
Copy link

Can you please add callbacks as options for valueField/labelField to access data? We use nested data structure so need something like: labelField={(item) => { return item.attributes.name;}}

Currently you're just assuming data structure are flat.

@sanusart
Copy link
Owner

@johnpittman feels like an age case. Can't you just re-map the options to the desired structure before you pass it to options prop? Something like the following should do the job:

const newOptions = () =>
    oldOptions.map(item => ({
      label: item.attributes.name,
      value: item.email
    }));

...

return (
  <Select
     options={newOptions}
     onChange={() => null}
  />
);

@johnpittman
Copy link
Author

johnpittman commented Jul 16, 2019 via email

@sanusart
Copy link
Owner

sanusart commented Jul 17, 2019 via email

@sanusart
Copy link
Owner

sanusart commented Jul 17, 2019

@johnpittman So this is very similar to original request, you can specify path instead of a string to access nested property. e.g.

<Select 
  valueField="attributes.name"
  labelField="attributes.name" 
  options={options}
  onChange={() => null}
/>

It is significant change to the code base and I want to keep testing it a bit more, so gonna keep it in the branch for some time. You may check it from the branch on your project if you want with loading it from branch:

npm uninstall --save react-dropdown-select && npm install --save react-dropdown-select#experimental-suppot-for-dotted-path-to-access-labelFiels-and-valueField

sanusart added a commit that referenced this issue Jul 19, 2019
#18)

* FIX (label, value): allow dotted path in valueField, labelField, searchBy and sortBy  issue #17
@sanusart
Copy link
Owner

Available since v3.2.0
Example of usage here

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