defined attributes in SQLAjqGridWidget

60 views
Skip to first unread message

jeetu

unread,
Aug 17, 2012, 12:14:56 AM8/17/12
to toscawidge...@googlegroups.com
I have a sqlalchemy table defined like follows

class Album(DeclarativeBase):

    # Name of mapped db table
    __tablename__ = 'material'
    id = Column(Integer, primary_key=True)
    name = Column(Unicode(50), nullable=False, unique=True)
    @memoized_property
    def total_sales(self):
        do some calculation here
        return result

When I use tw2.sqla.DbListPage I can see the total_sales column like this

class AlbumIndex(tw2.sqla.DbListPage):
    entity = model.Album
    newlink = twf.LinkField(link='/album/album', text='New', value=1)

    class child(twf.GridLayout):
        name = twf.LabelField()
        total_sales = twf.LabelField()

But when I use tw2.jqplugins.jqgrid.SQLAjqGridWidget, the total_sales is not visible. Based on the naming of the classes, it seems that both are based on sqla only. Then why this discrepancy, or I am missing out on something. the ajqgrid looks very nice, but is it not possible to show defined attributes like total_sales column?

Ralph Bean

unread,
Aug 17, 2012, 10:22:37 AM8/17/12
to toscawidge...@googlegroups.com
Hi,

For starters, here's the code that produces the data for that
widget:

https://github.com/toscawidgets/tw2.jqplugins.jqgrid/blob/develop/tw2/jqplugins/jqgrid/widgets/sqla.py

I haven't played with it in a while, but I think you might be able
to override "colModel" and get what you want. Unfortunately, I have
never tried this and have no examples for you. ;)

Alternatively, you could try a patch at including memoized
properties to the list of attributes that get automatically included
and displayed. That would be excellent, but likely much more work.

-Ralph

jeetu

unread,
Aug 20, 2012, 12:46:12 AM8/20/12
to toscawidge...@googlegroups.com
I tried using colModel values but I am not able to get the total_sales visible.

pager_options = {
        "colModel": [{ "name": "name"}, {"name":"total_sales"}],
        "colNames":["name", "total_sales"],
}

Or do I have to literally override the colModel?

Ralph Bean

unread,
Aug 20, 2012, 9:19:39 AM8/20/12
to toscawidge...@googlegroups.com
On Sun, Aug 19, 2012 at 09:46:12PM -0700, jeetu wrote:
> I tried using colModel values but I am not able to get the total_sales
> visible.
>
> pager_options = {
> "colModel": [{ "name": "name"}, {"name":"total_sales"}],
> "colNames":["name", "total_sales"],
> }
>
> Or do I have to literally override the colModel?

Literally overriding it is what I had in mind. If you see
:meth:`_get_metadata` here: http://bit.ly/QSrnEg It uses
:meth:`_make_model` across only the properties. If you override
cls.colModel with your own custom list of dicts, the widget would use
yours instead of building its own.

Alternatively, you could override :meth:`_get_properties` to return
all the properties plus a reference to "total_sales". Then the widget
should (hopefully) build its own colModel including your computed
column. See here for _get_properties -> http://bit.ly/QSs8gA
Reply all
Reply to author
Forward
0 new messages