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

Added prop defaultValue so users can display a default value for empty data #1487

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bradleysmagacz
Copy link

In some cases, the user may want to display a default value in the table if no data is available instead of a blank value. The user can add a 'defaultValue' prop to the BootstrapTable component if need be.

@AllenFang
Copy link
Owner

AllenFang commented Jul 19, 2017

HI @bradleysmagacz so this default value will be apply on every columns when data is empty array on BootstrapTable?

@bradleysmagacz
Copy link
Author

Hi @AllenFang, this will actually only apply at object key level. For example, lets say I have an array of objects that look like this:

[{ name: 'Greg', level: 1 }, { name: 'John', level: 2, weight: 180 }]

And let's say the user passes in 'No Data' as the defaultValue prop. When the table renders, Greg's weight will be set to 'No Data' instead of an empty field. If the user does not pass in a defaultValue prop, everything will function as before.

Although it's not a common use case, there are situations in our application where we need to render a default value when the object key does not exist or no data is available.

@AllenFang
Copy link
Owner

@bradleysmagacz, I see, thanks your descriptions 👍

@AllenFang
Copy link
Owner

AllenFang commented Jul 23, 2017

HI @bradleysmagacz , after review, I think the defaultValue should be depend on every different TableHeaderColumn, for your above example, weight may have 50 as default, level may have 1 as default and so on, so could you please have me to change for this? If you dont know how to handle it, I can help you, but just let me know, thanks 👍

Copy link
Owner

@AllenFang AllenFang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradleysmagacz
Copy link
Author

Hi @AllenFang. How can the defaultValue prop be passed down to TableColumn, where the data value is being rendered, if the prop is being passed into TableHeaderColumn? Currently I only see a way to pass down the defaultValue prop to TableColumn through TableBody.

@stephanebarbey
Copy link

If I may add something: I'd rather have the default value be a PropTypes.func than a PropTypes.string, so that we can make it work nicely if sorting or filtering is invoked (the value for a cell may be a Date or a number.)

@stephanebarbey
Copy link

Also: don't you want this default value to be proposed (by default) in the Add Row dialog? (This is what I would understand of a column's default value.)

@AllenFang
Copy link
Owner

@bradleysmagacz

  1. get the defined on here, this function transfer each props on TableHeaderColumns into an plan object.

  2. Actually, I already pass the columns object into TableBody, here, so you can get each columns props data in the TableBody.

  3. here render the TableColumn, so you can pass the default value into it.

Let me know if you still have any questions, thanks

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

Successfully merging this pull request may close these issues.

None yet

3 participants