Re: Sorting Integer value treeview column




Thanks.

Every time I used G_TYPE_INT in the gtk_list_store_new function the value returned wasnt the INT as expected. The value shown was an 8 digit number that didnt have any relation to the int as shown in the mysql client. I believe it was a pointer.

So I tried using a double (G_TYPE_DOUBLE) and adding the data via : 2, g_ascii_strtod(db_row[2], NULL),

I got the desired result, although it did padd the result with trailing zeroes...
So the program was behaving with the results...

So I tried one last version...Typeing with INT64... (G_TYPE_INT64)
and hooking the database value returned with the function:

2, g_ascii_strtoull(db_row[2], NULL, 10 ),

TADA! The value dispayed in the list was the integer I expected. The sort of the list worked a treat!

Just a pointer for those who might have the same problems...



David Nec(as (Yeti) wrote:
On Sat, May 05, 2007 at 06:20:05PM +0800, Jason Brisbane wrote:
I have a treeview that is populated with an Integer value (from a mysql database) that is populated into a G_TYPE_STRING.

Why?  Inappropriate data representation is the source of all
your problems.

This displays correctly but the sort function using:
          gtk_tree_view_column_set_sort_column_id (col, x);
          gtk_tree_view_column_set_sort_indicator (col, TRUE);

sorts the values as Alphanumeric, not numeric.
...

Do I need to hook in a Sort function and use the Modelsort instead of Model?

You do if you want to keep integers represented as strings.

Should sorting a integer value be a basic function of a treeview/liststore?

It *can* sort by integer columns.  GtkCellRendererText can
even diplay (format) a G_TYPE_INT column without the need of
an explicitly set cell data function.

But if you want to sort strings by some random associated
value you have to tell it how to compare these values.

Should I be setting an attribute of the column as "integer" instead of "text"?

No, you should use integer data model (i.e. G_TYPE_INT) for
integers.  If you need to present them as text, format them
to text: either by using GtkCellRendererText built-in
capabilities or an explicite cell data function that sets
the "text" attribute.

If rendering the presentation is very expensive, you may
want to cache the presentations in the model *in addition*
to the primary value, but this is not the case anyway.

I attach a simple program that demonstrates sorting by
two integer columns: one presented as plain number the other
as date+time.

Yeti

--
http://gwyddion.net/


<SNIP>

--
---
Regards,

Jason Brisbane




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]