Hello Anthony,

Thanks for your patience :)

Here is the code:

*MODEL*

db.define_table('t_owner',
    Field('f_name', type='string', label=T('Name')),
    Field('f_lastname', type='string', label=T('Lastname')),auth.signature,
    format='%(f_name)s',
    migrate=settings.migrate)

db.define_table('t_pet',
    Field('f_name', type='string', label=T('Name')),
    Field('f_animal', type='string', label=T('Animal')),
    Field('f_breed', type='string', label=T('Breed')),
    Field('f_owner', type='reference t_owner', label=T('Owner')),
    auth.signature,
    format='%(f_name)s',
    migrate=settings.migrate)

*COMPONENT ACTION*
@auth.requires_login()
def pet_component():
itemid = request.args[0]
q = db.t_pet.f_owner == itemid
db.t_pet.f_owner.default = itemid
db.t_pet.f_owner.writable = False
form = SQLFORM.grid(q,args=request.args[:1],csv=False)
return locals()

*pet_component.load : *
<div class="myclass">
{{=form}}
</div>

*ACTION THAT USES THE COMPONENT:*
@auth.requires_login()
def all_manage():
owner_forms =[]
ids = []
qowner = db.t_owner.id>0
owners = db(qowner).select()
for i,el in enumerate(owners):
owner_forms.append(SQLFORM.grid(db.t_owner.id==el.id,
fields=[db.t_owner.f_name,db.t_owner.f_lastname],sortable=False,details=False,create=False,
searchable=False,csv=False,deletable=False,editable=False))
ids.append(el.id)
return locals()

*all_manage.html view:*
{{extend 'layout.html'}}

<h2>All Manage</h2><p>
{{for i,el in enumerate(owner_forms):}}
{{=el}}
{{ids[i]}}
{{=LOAD('default','pet_component.load',args=ids[i], ajax=True)}}
{{pass}}

Let me know if you find something. Thanks a lot.

Clara




On Mon, Dec 15, 2014 at 2:50 PM, Anthony <[email protected]> wrote:
>
> Probably need to see the code.
>
> On Monday, December 15, 2014 12:36:16 PM UTC-5, clara wrote:
>>
>> Hello Anthony,
>>
>> It did work!!! Thanks !
>>
>> Now, something does not work well when adding records into the grid
>> component: I restrict the "owner" so that the record should be appended to
>> the same grid. Now I enter the record, it gets recorded successfully but
>> the grid (in which I added the record) updates to the largest ID (it looks
>> like the last grid in the view). If I refresh the view, everything is in
>> order. Do I need to do something else? Could this be a bug?
>>
>> I can send the code in if needed. Thanks again for the great support.
>>
>> Clara
>>
>>
>>
>> El lunes, 15 de diciembre de 2014 12:19:36 UTC-3, Anthony escribió:
>>>
>>> The way you're doing it (with the adjustment I suggested) should work.
>>> Are you still having problems?
>>>
>>> Anthony
>>>
>>> On Monday, December 15, 2014 9:25:27 AM UTC-5, clara wrote:
>>>>
>>>> Hello Anthony,
>>>>
>>>> Thanks for your reply. I am trying to pass *itemid* to the component.
>>>> How do I do that?
>>>>
>>>> Basically imagine a model like>
>>>> db.define_table('person',
>>>>                 Field('firstname'),
>>>>                 Field('lastname'), format='%(firstname)s %(lastname)s')
>>>> db.define_table('dog',
>>>>                 Field('name'),
>>>>                 Field('owner',db.person))
>>>>
>>>> and what I want to generate is a view where there is every person
>>>> listed and each person has a grid below with the dogs it owns. I figured
>>>> components would be the best approach, but I don't know how to pass a
>>>> parameter (the owner ID, for the example model) to the component.
>>>>
>>>> Thanks,
>>>>
>>>> Clara
>>>>
>>>>
>>>> El domingo, 14 de diciembre de 2014 23:43:24 UTC-3, Anthony escribió:
>>>>>
>>>>> The grid makes use of URL args, so if the base URL of the grid action
>>>>> also includes args, you must tell the grid to preserve those extra-grid
>>>>> args via its "args" argument:
>>>>>
>>>>> form = SQLFORM.grid(db.address.client == itemid, args=request.args[:1
>>>>> ])
>>>>>
>>>>> Anthony
>>>>>
>>>>> On Sunday, December 14, 2014 2:54:06 PM UTC-5, clara wrote:
>>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I would like to see an example of a component with an argument. I
>>>>>> tried it with no luck, If I define the component without arguments it 
>>>>>> works
>>>>>> fine but if I add an argument loading the page that has the component 
>>>>>> leads
>>>>>> to some kind of infinite recursion. Any help on this would be 
>>>>>> appreciated.
>>>>>> To be more explicit:
>>>>>>
>>>>>> in the controller:
>>>>>> @auth.requires_login()
>>>>>> def component_action():
>>>>>>     itemid = request.args(0)
>>>>>>     form = SQLFORM.grid(db.address.client==itemid)
>>>>>>     return dict(form=form)
>>>>>>
>>>>>> in views:
>>>>>> I create a "component_action.load":
>>>>>>
>>>>>> <div class="manage_things2">
>>>>>> {{=form}}
>>>>>> </div>
>>>>>>
>>>>>> I use the component in another action adding to the action's HTML:
>>>>>> {{=LOAD('default','component_action.load',args=2, ajax=True)}}
>>>>>>
>>>>>> Is there anything awefully wrong in this?
>>>>>>
>>>>>> I will appreciate your help. Thanks!
>>>>>>
>>>>>> Clara
>>>>>>
>>>>>>
>>>>>>  --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/duKdi15aRcE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to