How do I add an 'add' button for adding details in database when using servlet jdbc as backend?

How do I add an 'add' button for adding details in database when using servlet jdbc as backend?

rudrajitrudrajit Posts: 18Questions: 5Answers: 0

as in I have searched for it but didnt find any such example.
I am using the datatable inside jsp.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Just to be clear, is this using Editor? Or some other mechanism? If Editor, this thread might help,

    Colin

  • rudrajitrudrajit Posts: 18Questions: 5Answers: 0

    No, actually I just want the add button to open a pop -up , i.e the modal (bootstrap)
    As i can edit the modal as per my wish.

  • kthorngrenkthorngren Posts: 20,298Questions: 26Answers: 4,769
    edited November 2020

    Are you saving the new data to the server or just the client?

    If just in the client use row.add() to add the new row to the Datatable.

    If saving to the server via ajax you have a couple options:

    1. Have the server return the inserted row and in the ajax() success function use row.add() to insert the returned data. This would similar to how Editor behaves.
    2. In the ajax() success function use ajax.reload() to have Datatables refresh the entire data set.

    If this doesn't help then please provide more details of how you want this to work.

    Kevin

  • rudrajitrudrajit Posts: 18Questions: 5Answers: 0

    Ok... so I have this button which opens a form and I can retrieve the data from it to add it in the database.-

    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
      ADD
    </button>
    
    <!-- Modal -->
    <div class="modal " id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
      <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLongTitle">ADD</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <div class="container">
                <form action="${pageContext.request.contextPath}/Ord_Details" method="POST">
                    Order ID  <input type="text" name="Oid" ><br>
                    Order Date  <input type="text" name="Odt" ><br>
                    Customer Name  <input type="text" name="Cname" ><br>
                    Customer Number  <input type="text" name="Cno" ><br>
                    Order Amount  <input type="text" name="Oamt" ><br>
                    Notes  <input type="text" name="Notes" ><br>
                    <button type="submit" class="btn btn-primary">Save changes</button>
                </form>
            </div>
          </div>
        </div>
      </div>
    </div>
    

    And I want to know if I can achieve the modal functionality inside the buttons provided inside data table.

    such as add a custom button inside which open a modal(pop-up) .
    Basic code inside js-

    dom: 'Bfrtip',
              buttons: [
                  'copy', 'csv'
              ],
    
  • kthorngrenkthorngren Posts: 20,298Questions: 26Answers: 4,769
    Answer ✓

    You can create a custom button to option the form, like this example.

    Kevin

  • rudrajitrudrajit Posts: 18Questions: 5Answers: 0

    Yes , Thank you, I looked into it and it works now.

This discussion has been closed.