Direct editing inside a grid

83 views
Skip to first unread message

Serge Bourgeois

unread,
Jul 17, 2014, 10:25:20 AM7/17/14
to web...@googlegroups.com
Hello,

In order to simplify the user interface of basic controller functions, I want to offer direct editing in SQLFORM.smartgrid, using the same widgets (string, options, uploads, ...) than those available in create or edit.

Maybe, I missed the point in the doc?

Thank you for any advice.

Serge

Anthony

unread,
Jul 17, 2014, 11:21:05 AM7/17/14
to web...@googlegroups.com
This is not available out of the box, though it would be nice.

Anthony

Serge Bourgeois

unread,
Jul 17, 2014, 12:18:39 PM7/17/14
to web...@googlegroups.com
Thanks Antony!. Do you know if there is any plan to develop such a feature? If yes, do you have any idea of availability ?

Still a third question: I tried the idea proposed here :

http://www.web2pyslices.com/slice/show/1928/basic-inline-editing-in-sqlformgrid-no-plugin-no-javascript

but, I got a message saying that I couldn't change the objects already existing ... (I guess the name of the fields, even with migrate == False).

Maybe you have any good idea to turn around this issue?

Serge

Anthony

unread,
Jul 17, 2014, 3:57:12 PM7/17/14
to web...@googlegroups.com
I don't have time to look into it, but seeing some code and a traceback might help.

Anthony

Manuele Pesenti

unread,
Jul 18, 2014, 1:38:28 AM7/18/14
to web...@googlegroups.com
Il 17/07/14 18:18, Serge Bourgeois ha scritto:
> but, I got a message saying that I couldn't change the objects already
> existing ...
look for a validator... in case you are using IS_NOT_IN_DB it happens
that when you're not updateing a value in a field with this validator
but other, because of the whole record will be submitted for update, the
value not modified is considered in the query because already in db and
that cause the error.
A solution coud be to rewrithe the query passed to the validator on the
fly when you are in edit mode...

Hope it could help

Cheers

M.

Serge Bourgeois

unread,
Jul 18, 2014, 6:02:07 AM7/18/14
to web...@googlegroups.com
Hello,

I could sort it out...

For those who could be interrested, here under the key elements of my solution.

1. In the model, create the following functions (here for string and drop list):

def options_widget(field,value,**kwargs):
    return SQLFORM.widgets.options.widget(field,value,_class="generic-widget",**kwargs)

def string_widget(field,value,**kwargs):
    return SQLFORM.widgets.string.widget(field,value,_class='string',**kwargs )


In the controller, in the function that you want to contain the editing grid:
def my_function_name(): # here my tale name = t_txw_expense_template
    if len(request.post_vars) >0:
        for key, value in request.post_vars.iteritems():
            (field_name,sep,row_id) = key.partition('_row_') # field_name will look like field_name_row_99
            if row_id:
                db(db.t_txw_expense_template.id == row_id).update(**{field_name:value})
   # the name of the attribute is used to know which row is involved

# for each field that you want to see:

    db.t_txw_expense_template.f_expense_template.represent = lambda value, row: string_widget(db.t_txw_expense_template.f_expense_template, value,
                                                                                              **{'_name':'f_expense_template_row_%s' % row.id})
    
    db.t_txw_expense_template.f_header.represent = lambda value, row: string_widget(db.t_txw_expense_template.f_header, value,   
                                                                                              **{'_name':'f_header_row_%s' % row.id})
    
    db.t_txw_expense_template.f_project.represent = lambda value, row: options_widget(db.t_txw_expense_template.f_project, value,   
                                                                                              **{'_name':'f_project_row_%s' % row.id})
    
 # and so on...
 form = SQLFORM.smartgrid(db.t_txw_expense_template, # and so on...
                                # selectable = dict(t_txw_expense_template= None)
                             selectable= lambda ids : redirect(URL('my_function_name',vars=request._get_vars)),                      
                             )
      #remove selectable's checkboxes
    form.elements(_type='checkbox',_name='records',replace=None)
    return dict (form = form)
Hope this can help...
Reply all
Reply to author
Forward
0 new messages