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

b:dataTableColumn sorting BigDecimal #786

Closed
algiorgi opened this issue May 17, 2017 · 8 comments
Closed

b:dataTableColumn sorting BigDecimal #786

algiorgi opened this issue May 17, 2017 · 8 comments
Assignees
Milestone

Comments

@algiorgi
Copy link

algiorgi commented May 17, 2017

First of all, sorry for my bad English.

I'm having an issue sorting prices with format in a b:dataTableColumn. The price attribute of my item is a BigDecimal.

Here a snippet of the code:

              <b:dataTableColumn label="Price" data-order="#{item.price}">
                    <h:outputText value="#{item.price}">
                        <f:convertNumber type="currency" currencySymbol="$" />
                    </h:outputText>
                </b:dataTableColumn>

Here I show the result:
sorted

Note:

I can sort the items perfectly deleting the h:outputText
This is the working code:

<b:dataTableColumn label="Price" value="#{item.price}" data-order="#{item.price}"/>

but I wanna give some format to my prices

I´m using bootsfaces 1.0.1

Thanks and great job. If you need something else please tell me.

Alejandro

@stephanrauh
Copy link
Collaborator

If you're concerned about your English, feel free to write in Spanish. Currently, the entire BootsFaces team speaks Spanish well enough. But judging from this ticket, you're English is better than you think, too :).

@stephanrauh
Copy link
Collaborator

Looks like something we have to investigate. I was sure that it's possible to combine the data-order attribute and nested HTML code. If I get you right, that's precisely what does not work. That'd be annoying.

@stephanrauh
Copy link
Collaborator

BTW, probably a simple work-around looks like so:

<b:dataTableColumn label="Price" value="$#{item.formattedPrice} " data-order="#{item.price}"/>

In this case, you'd have to implement a special getter getFormattedPrice() in the Java bean. The idea is to implement the formatting in this getter instead of using a predefined converter. Whether you add the "$" in the EL expression like I've shown above, or if you add it in the getFormattedPrice() method, it up to you (and your usecase).

@algiorgi
Copy link
Author

Hey! Thanks for the reply.

Yes, I thought it. Just I tried to re use the converter tag.

But look at it. I made a little change on my code. I deleted the <f:convertNumber type="currency" currencySymbol="$" /> tag

<b:dataTableColumn label="Precio">
    $<h:outputText value="#{elemento.precio}"/>
</b:dataTableColumn>

And now the sorting feature works great:
sorted_working

@stephanrauh
Copy link
Collaborator

That's really astonishing! Only - I tried your original code with our showcase, and it seems to work, too. Something must be different, but I wonder what?

      <h:form>
            <b:dataTable value="#{carPool.carPool}"
                         var="car"
                         onpage="console.log('page');">
                <b:dataTableColumn value="#{car.brand}" />
                <b:dataTableColumn value="#{car.type}" />
                <b:dataTableColumn value="#{car.color}" />
                <b:dataTableColumn value="#{car.year}"  order="asc" />
                <b:dataTableColumn label="precio" data-order="#{car.price}">
                	<h:outputText value="#{car.price}">
                		<f:convertNumber type="currency" currencySymbol="$" locale="en_US"/>
                	</h:outputText>
                </b:dataTableColumn>
                <b:dataTableColumn value="#{car.enginePower}" label="Engine Power (hp)" />
            </b:dataTable>
        </h:form>

image

@stephanrauh
Copy link
Collaborator

Setting the locale to "es" doesn't make any difference. The "$" is displayed before the currency, and the decimal point is a comma. But still, the sort order seems to work.

@algiorgi
Copy link
Author

Sorry for my delay.

I see, it works great. Moreover, I created a simple project with a minimal set of dependencies and I can not reproduce my own case.

So, it must be closed. Sorry for waste your time.

In other hand, I realized that our prices are printed in a different way:
Your example: $1,969.00 (the correct way, BTW)
My case: $1.800,00 (Bad format)

So, I have an issue in other place, maybe when I mapping the database field to my entity. I will check it.

Thanks a lot!

@stephanrauh
Copy link
Collaborator

I didn't consider it a waste of time :).

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

2 participants