Re: EuGTK:Sorting Column of Floats

new topic     » goto parent     » topic index » view thread      » older message » newer message
euphoric said...

I'm using a gSTR to display a price column, but when I sort, it's sorting alphabetically instead of numerically.

Trying to use gFLT just shows 0.00000000 for every row. getlost

I thought I saw a reference somewhere about sorting columns the proper way depending on the content, but now I can't find it.

I'll keep looking, but how do I sort a column of floats that are actually gSTRs?

See this sample:

Sort by the Price column.

The gFLT and gDBL were left out of the change I made when I added the recursive function. Wasn't sure recursion was going to work. Will send an update asap.

That's why I asked earlier whether you needed to use actual atoms/integers, or could deal with string versions of the value.

There are several things at work here: GTK's default display for floats (i.e. dollar amounts) is not good. There are too many decimal places. You need to format the value more neatly, and perhaps add a dollar sign or whatever.

But of course doing that means the sorting is going to be off. Because the sort is based on what you see in the column.

One way is to create 2 columns, one defined as gSTR, the other defined as gFLT. Both get their values from the same column of data.

You hide the gFLT column, but sort on that column when you click on the one with the formatted values.

These hidden columns can be useful in all sorts of ways (control the color or text of the rows, sort on some combination of values, etc. Or finding all categories which have something in common: e.g. you type "shoes" into a search box, and all categories with "shoes" rise to the top: "Mens shoes" "Womens shoes" "Brake shoes" "Shoeshine kits" ...

That's probably the easiest way, but only if the values aren't editable.

Other ways involve writing custom sort routines. Will work on that tonight.

new topic     » goto parent     » topic index » view thread      » older message » newer message


Quick Links

User menu

Not signed in.

Misc Menu