Skip to content

Default value not working for select filter in remote mode #1025

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

Closed
BenoitAverty opened this issue Feb 10, 2017 · 4 comments
Closed

Default value not working for select filter in remote mode #1025

BenoitAverty opened this issue Feb 10, 2017 · 4 comments

Comments

@BenoitAverty
Copy link
Contributor

I have a table with two enum columns, And I added a filter on them (the table is in remote mode).

Here is a piece of my code :

<TableHeaderColumn dataField="customerType" dataSort
  filter={{ type: 'SelectFilter', options: zipObj(props.customerTypes, props.customerTypes),
  defaultValue: filterDefaults.customerType }}
>
  Type
</TableHeaderColumn>

The options object looks like this (zipObj if from the ramda library):

{
  'EASY': 'EASY',
  'SIR': 'SIR'
}

and the defaultValue is 'EASY'.

I noticed in the code that you use the defaultValue attribute on the select tag, but I think it should just be value. (See here : https://github.com/AllenFang/react-bootstrap-table/blob/master/src/filters/Select.js#L63)

I tried to change this in my node_modules folder and the right option was selected, but then it had some strange behaviors, the style was the same as when the placeholder is selected, and I couldn't select the placeholder anymore.

Can you help me figure out what's wrong if it's my code, or publish a fix to this problem ? I'm more than happy to do a PR but I don't see the problem besides the defaultValue attribute.

@BenoitAverty
Copy link
Contributor Author

I investigated further, and I think the problem is partly cause by the fact that I load the data asynchronously, but the default value is memorized in my localstorage.

  • At the first render, the defaultValue is "SIR" (for example), but the options object is empty (so the placeholder is selected).
  • Then the parent component updates, which changes the options object. But in the "Select" component, the isPlaceholderSelected is only computed in the constructor.

I think there is something to do in a componentDidUpdate or componentWillReceiveProps function so that it works well in remote mode, where everything is controlled by the props.

@AllenFang
Copy link
Owner

AllenFang commented Feb 10, 2017

I think there is something to do in a componentDidUpdate or componentWillReceiveProps function so that it works well in remote mode, where everything is controlled by the props.

You are certainly right, maybe we need a componentWillReceiveProps in Select filter, I'll fix it in near future, because I'm busy in these day event at next two month, so I'm not sure when I can complete, anyway, PR is welcome

Let me know if you have any question or problems.

@AllenFang
Copy link
Owner

Fixed on v3.0.0-beta.12, BTW, v3.0.0 ready to end the beta, will be release to production recently

@9005
Copy link

9005 commented Jan 31, 2018

@AllenFang : Hi Allen , I am using remote = true and fetchTotalData . Select Filter is not working for me.
If I remove remote = true then its working.
Below is code :

<TableHeaderColumn dataField='verifyGuestUiid' filterFormatted dataFormat={ this.enumFormatter } formatExtraData={ qualityType } filter={ { type: 'SelectFilter', options: qualityType } }>UIID

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

No branches or pull requests

3 participants