Hello!
I'm having troubles to load an SQLFORM grid in an ajax component and then
redirect to another whole page.
First, the controller:
This controller create a FORM and send it to the view. Once the user press
the submit button, is loaded a grid .
def consulta_por_numero_tipo_asunto():
# Se crea la parte fija del form
variable_form=DIV(
LABEL('Escribe un número de asunto ',
_for="input_numero_asunto"),
INPUT(_type="text", _name="numero_asunto", _value="",
_id="input_numero_asunto", _class="buscar"),
FIELDSET(
LEGEND("Rango de fechas",
LABEL('del', _for="del"),
INPUT(_type="text", _name="del", _id="del",
_value="", _class='date'), # _class="date" hace que se utilice el widget
date de SQLFORM
LABEL('al', _for="al"),
INPUT(_type="text", _name="al", _id="al",
_value="", _class='date'), # _class="date" hace que se utilice el widget
date de SQLFORM
) # fin LEGEND
) # fin FIELDSET
,_id="numero_y_rango") # fin DIV
form = FORM(variable_form, _id="form_buscar_por_numero_asunto") #fin
FORM
# Se crea la parte variable del form compuesta por la lista de los
tipos de gastos guardados en la base de datos
gastos=db2(db2.gastos).select(orderby=db2.gastos.nombre)
tipos_gastos_list=[]
for g in gastos:
tipos_gastos_list += [INPUT(_type="checkbox", _name="lista_gastos")]
tipos_gastos_list += [" " + g.nombre]
tipos_gastos_list += [" (" + g.abreviatura +")"]
tipos_gastos_list += [BR()]
variable_form.append(FIELDSET(LEGEND('Selecciona tipo de asunto',
DIV(tipos_gastos_list, _id="l_gastos"), _for="l_gastos")))
variable_form.append(INPUT(_type="submit", _name="enviar",
_value="Enviar"))
if form.validate():
pass
return dict(orm=form)
The view(consulta_por_numero_tipo_asunto.html):
{{extend 'layout.html'}}
<div id="form_buscar">
{{=form}}
</div>
<div id="resultados_busqueda">
<h4>Resultados de la búsqueda</h4>
<div id="tabla_resultados_busqueda">
</div>
</div>
<script>
jQuery('#form_buscar_por_numero_asunto').submit(function() {
var valor_num_asunto= jQuery("#input_numero_asunto").val();
ajax('{{=URL('default',
'busca_consulta_por_numero_tipo_asunto')}}',['numero_asunto'],
'tabla_resultados_busqueda');
return false;
});
</script>
This function load the SQLFORM grid:
def busca_consulta_por_numero_tipo_asunto():
num_asunto=request.vars.numero_asunto
grid = SQLFORM.grid(db2.numeros_asunto, selectable = lambda ids :
redirect(URL('default', 'modificar_numero_asunto', args=ids),
extension=False, client_side=True))
return dict(grid=grid)
This code works well, but when the user select a row of the grid, the grid
MUST to redirect to another page, but, reload the same page
consulta_por_numero_tipo_asunto.html
Can anyone help me? I would be very grateful.
Regards
--
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.