簡體   English   中英

Ruby on Rails數據表刷新

[英]Ruby on rails Datatables refresh

當您單擊按鈕時,我嘗試更新數據表。 我在“ spr_well_types.js.coffee”中的JQuery代碼:

jQuery ->  
   sprWellTable = $('#spr_well_types').dataTable
      sPaginationType: "full_numbers"
      bJQueryUI: true
      bProcessing: true
      bServerSide: true
      sAjaxSource: $('#spr_well_types').data('source')

$(document).ready ->
  $("#Refresh").on "click", (event) ->
    sprWellTable.fnDraw()

我的頁面“ index.html.erb”:

<button id="Refresh" type="button">Refresh</button>
<table id="spr_well_types" class="display" data-source="<%= spr_well_types_url(format: "json")%>">
  <thead>
    <tr>
      <th>Name</th>
      <th>Short Name</th>
      <th>Lock version</th>
    </tr>
  </thead>
  <tbody>

  </tbody>
</table>

代碼我單擊瀏覽器錯誤中的“刷新”按鈕“ ReferenceError:未定義sprWellTable”。 我看到了主題 ,但是代碼:

$("#Refresh").click ->
  sprWellTable.fnDraw()

不綁定到刷新按鈕。

我找到了解決方案:

$(document).ready ->
  $("#Refresh").on "click", (event) ->
    $("#spr_well_types").dataTable().fnDraw()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM