Does anyone know why removing all rows triggers a request to my server?

Does anyone know why removing all rows triggers a request to my server?

ak47ak47 Posts: 16Questions: 5Answers: 2
edited October 2014 in Free community support

This is for version 1.9.4. I have a table declared like this:

researchTable = $("#research_table").dataTable
    iDisplayLength: 25
    bPaginate: true
    bLengthChange: true
    bFilter: true
    bSort: true
    bServerSide: false
    bInfo: true
    bJQueryUI: true
    bProcessing: true
    sDom: "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>"
    sPaginationType: "bootstrap"

Use case is a user enters a term into a single field, and application searches database for that term and returns values. Button code is:

$("#research_button").click ->
  data = { term: $("#research_term").val() }
  hash = { type: "GET", url: "search", data: data }
  $.ajax(hash)
  false

Works perfectly. Except of course that every time a new term is searched, the results are added to the previous set. This is a very, very simple use case. However, adding this:

$("#research_button").click ->
  $("#research_table").dataTable().rows().remove();
  data = { term: $("#research_term").val() }
  hash = { type: "GET", url: "search", data: data }
  $.ajax(hash)
  false

That one line, with .rows().remove() in it, literally triggers a request to my server. This is not a serverside table. Does anyone know why this is happening? So far I can't find a single way to clear out the data in the table. It keeps sending a request to my server, which is totally bizarre.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    This is for version 1.9.4

    and

    $("#research_table").dataTable().rows().remove();

    rows().remove() is a 1.10 API.

    To clear the data in the table in the legacy versions use fnClearTable .

    Allan

This discussion has been closed.