On Saturday, May 25, 2019 at 6:59:44 PM UTC-7, Cristina Sig wrote:
>
> Hello everyone,
>
> I have a table filled with records from a database. 
>
> Also, I have a button to add a new record. Once I enter all the data for 
> the new record and press the submit button, I want to update the content of 
> the table without reloading the page (without F5).
>
> I'm struggling to find a solution to this so any suggestions would be 
> welcomed.
>
>
>
Sounds like a job for jQuery or for the LOAD() helper .  I use one to have 
a secondary form on the same page as another; the DIV used by the LOAD gets 
refreshed when I submit the secondayr form, but the page doesn't relaod.

<URL:https://web2py.com/books/default/chapter/29/11/jquery-and-ajax#>
<URL:https://web2py.com/books/default/chapter/29/12/components-and-plugins#Components-LOAD-and-Ajax>

Good luck!

/dps

[original post continues]

Database
>
> db.define_table('Student',
>                 Field('name', 'string', label='Name'),
>                 Field('last_Name', 'string', label='Last Name'),
>                 Field('age', 'integer', label='Age'),
>                 Field('nationality', 'string', label='Nationality'),
>                )
>
>
> Controller (Tools.py)
>
> def studentNew():
>     formStudent=crud.create(db.Student)
>     if formStudent.accepted:
>         response.js = '(function($) 
> {$("#myModalADD").modal("hide");}(jQuery));'  //hide modal after press submit 
> button
>         response.flash = 'Record added successfully!' //displays message 
> after press submit
>     return dict(formStudent=formStudent)
>
>
> View
>
> <script>
>     $(document).ready(function(){
>        tabla= $('#table').DataTable( {
>            'scrollX': true,
>            'responsive':true,
>            'sRowSelect': "single",
>           });
> </script>
>
> <div id="some_btn"><a class="btn btn-success btn-mini" 
> data-target="#myModalADD" data-toggle="modal" 
> data-backdrop="static" data-keyboard="false">Add New Student</a></div>
>
> <table id="table" class="tablaC table-striped hover cell-border" 
> cellspacing="0" width="100%" >
>    <thead>
>        <tr>
>           <th>Name</th>
>           <th>Last Name</th>
>           <th>Age</th>
>           <th>Nationality</th>
>        </tr>
>     </thead>
>     <tbody>
>         {{for student in formListar:}}
>             <tr>
>                 <td>{{=student.Student.name}}</td>
>                 <td>{{=student.Student.last_name}}</td>
>                 <td>{{=student.Student.age}}</td>
>                 <td>{{=student.Student.nationality}}</td>
>             </tr>
>         {{pass}}
>     </tbody>
> </table>
>
> <div id="myModalADD" class="modal fade"> //Modal that contains the Add New 
> Student Form and Submit button
>   <div class="modal-dialog" role="document">
>     <div class="modal-content">
>       <div class="modal-header">
>        <h4 class="modal-title">Add New Student</h4>
>       </div>
>       <div class="modal-body"> {{=LOAD('Tools','studentNew', ajax=True, 
> ajax_trap=True)}}</div>
>       <div class="modal-footer">
>           <div class="col-md-6 col-md-offset-3 ">
>         <button type="button" id="cancelar" class="btn btn-secondary" 
> data-dismiss="modal">Cancel</button>
>          </div>
>       </div>
>     </div>
>   </div>
> </div>
>
>
>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/aa06f194-1787-4551-abc0-204e03b15146%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to