Any idea? thanks in advance
2010/3/25 Javier M. [email protected]:
Any idea? thanks in advance
Could you be more precise ? I don’t get what you want to do.
Simon
Sorry. My intention is to show the data from tables of database, that
the user can select. Therefore, a priori, I don’t know either the number
or type of the columns that I must show. The Question is how I can
dynamically create the ListStore.new, Now better?
Very grateful
2010/3/26 Javier M. [email protected]:
Sorry. My intention is to show the data from tables of database, that
the user can select. Therefore, a priori, I don’t know either the number
or type of the columns that I must show. The Question is how I can
dynamically create the ListStore.new, Now better?
Considering the pseudo table
User
id integer
name string
birth date
If you can get the type of columns, try to make a switch.
model_types = Array.new
table_attributes_type.each do |attribute_type|
case attribute_type
when ‘tinyint’, ‘integer’, ‘longint’
model_types << Numeric
when ‘varchar’, ‘text’
model_types << String
[…]
end
my_list_store = ListStore.new(model_types)
If you can’t have the types, you might put everything as string, and
do the conversion on the fly.
Calling ‘to_s’ when filling the model
Calling ‘to_i’, ‘to_f’, Date.parse, etc when reading from the model.
so the model would :
my_list_store = ListStore.new([String] * number_of _attributes)
Makes sense ?
Simon
Hei Simon,
you can find my approach here →
In short: i store the reference to the object in the first column, every
other field i want to display will be a string, so the ListStore.new
call looks something like:
ListStore.new([Object, [String] * no_of_fields_to_display].flatten)
On callbacks i do every operation on the object, the fields are just for
display. I don’t know if this is suitable to your case.
Bye!
–
Andrea D.
2010/4/8 Andrea D. [email protected]:
On callbacks i do every operation on the object, the fields are just for
display. I don’t know if this is suitable to your case.
It’s not my case, I’m just answering Javier :).
Thanks anyway.
I will have to take a look at freightrain, I’m mostly doing everything
by hand right now.
It would be nice to have a higher level lib, MVC style.
I don’t have much time though, unfortunately.
Simon
Oh, I am sorry I am very new to the mailing list, i guess the
original message was posted before i joined.
There’s no documentation for freightrain at the moment so I am aware
that it’s kind of difficult to understand how to use it. I am working on
that though, i hope i can put up a website with all needed to learn it
in a month or so. Thanks for the interest anyway!
Bye!
–
Andrea D.