Datatables use with Search Form

Datatables use with Search Form

ad11ad11 Posts: 3Questions: 1Answers: 0

I'd like users to enter data in a form that would be used to generate an ajax url. When the user clicks "Get" on the form, the table would appear with the appropriate data. Don't want the table to appear until the form is submitted the first time. Here are the desired steps:

  1. Load page, configure table, don't fire AJAX request.
  2. Enter search parameters
  3. Submit form.
  4. Use search parameters to formulate ajax url (i.e. "url": "/people?dept=acct")
  5. Display table.
  6. Change search parameters
  7. Submit form
  8. Use search parameters to formulate new ajax url (i.e. "url": "/people?dept=eng")
  9. Display table.

Please let me know an appropriate way to use jQuery to accomplish. Pseudo code is fine. Thanks very much.

Answers

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67

    You might find my yadcf plugin exFilterExternallyTriggered function usefull for your scenario

  • ad11ad11 Posts: 3Questions: 1Answers: 0
    edited August 2015

    Here's a solution that seems to work.

    1. Define the table:
      var table = $('#table1').DataTable({"columns": [as needed]})
      Use DataTable where D is capital
      Don't include ajax or data object definition.

    2. Load the data as follows:
      table.clear()
      table.rows.add( dataToBeAdded )
      table.draw()
      dataToBeAdded can be obtain through AJAX where the form data is used to query the server.

    If you don't want the table to be shown initially. Place the table in a div that is hidden. Unhide the div in step 2.

    Comments are very welcome.

This discussion has been closed.