Something like this (not tested):
<script>
$(function() {
$('select[name=account_list]').on('change', function() {
$.web2py.component('{{=URL('positions2', 'component_grid.load')}}' +
'?account=' + this.value,
target='grid');
});
});
</script>
{{=select_account_list}}
{{=LOAD('positions2', 'component_grid.load', ajax=True, target='grid')}}
That will initially load the grid via LOAD() into a div with id="grid". The
JS code creates an event handler for changes to the account_list select.
When a new option is selected, the component is re-loaded into the "grid"
div. The call to reload the component includes a query string with an
"account" variable holding the value of the selected option -- this can be
accessed via request.vars.account within the component_grid() function.
Anthony
On Friday, January 31, 2014 9:00:22 PM UTC-5, A36_Marty wrote:
>
> Thank you for your response. I've got components working and have a
> couple of follow-up questions -- mainly due to my ignorance and novice
> web2py abilities.
>
> 1) I see a args and vars option on the view-side component LOAD() function
> for the component; however, I'm having trouble with the view syntax.
>
> I have the following in my view:
>
> {{=select_account_list}}
> {{=LOAD('positions2','component_grid.load', ajax=True)}}
>
> The first line builds a SELECT with OPTIONS and drops it in,
> name=account_list
>
> The second list creates a grid that I'd like to base off the currently
> value of the SELECT.
>
> How can I get the value of the "account_list" SELECT and pass it to the
> component -- causing the grid to be refreshed and show the related records
> for the newly selected account?
>
> 2) <script> syntax, Onchange, etc...
>
> You mention calling "web2py.component". Could you provide the syntax for
> doing so, where to put it, etc. (I'm very new to w2p, jquery, etc.)
> I've googled a bunch but can't get it working on my end.
>
> I'm assuming you tie-in to the _onchange value of the select created by
> {{=select_accountlist}} that re-calls the LOAD() when something is changed?
>
> Many, many, many thanks for your guidance. I greatly appreciate it.
>
>
> On Friday, January 31, 2014 9:27:28 AM UTC-6, A36_Marty wrote:
>>
>>
>> <Controller>
>> def index():
>> select_list = (Create a SELECT of options with the
>> _onchange="ajax('ajax_requery',['selectlist'],'div_grid')
>>
>> grid = SQLFORM.grid(...)
>>
>> div_grid = DIV(grid, _id="div_grid")
>>
>> return dict(div_grid = div_grid, select_list=select_list)
>>
>> def ajax_requery():
>> #called by Ajax, returns grid, ajax() puts it in DIV = "div_grid"
>> grid = SQLFORM.grid(...)
>> return grid
>>
>> <View>
>>
>> {{=select_list}}
>> {{=div_grid}}
>>
>>
>> Issue I'm seeing:
>> On the 1st visit to the controller and I press "Add" on the grid, and all
>> works well. The browser is sent to:
>> /App/controller/index/new/... A create form is created by the grid...
>>
>> If I change the select list and cause the ajax function (ajax_requery) to
>> put a new grid into the DIV "div_grid", then press "Add" on the inserted
>> grid, the _href on the "Add" button causes the browser to be sent to:
>> /App/controller/*ajax_requery*/new... Causing the grid to fail
>>
>> I feel like I'm missing a best practice design pattern and wanted to ask
>> the best way to accomplish the above. I could go in with the DOM and
>> edit the _href of the grid button, but that seems pretty hacky... Figure
>> there's a better way.
>>
>> Thanks in advance.
>>
>
--
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/groups/opt_out.