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.


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/3dc1794f-9cb4-4e39-8201-3ab9ab04a9ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to