2014-07-15 35 views
0

我正在使用分頁,搜索和可點擊行的bootstap-table的實現。當搜索過濾器未被使用時,該表格按預期工作,即,當該行被點擊時,該表格會轉到正確的鏈接。然而,當使用搜索過濾器時,表格的邏輯認爲第一行仍然是第一個項目,這不是真實的,因爲它基於用戶輸入。使用搜索過濾器時,引導表刷新jQuery?

有沒有一種方法可以在輸入字段中的按鍵事件上刷新jQuery,請記住,搜索的輸入字段位於bootstrap-table.js文件中?

HTML/Django的代碼

<link href={% static "css/bootstrap-table.css" %} rel="stylesheet"> 
<script type="text/javascript" src={% static "js/bootstrap-table.js"%}></script> 

<h1>Book Exchange Library</h1> 

<table class="table table-condensed" id="table" data-url={% static "json/data.json" %} data-height="619" data-pagination="true" data-search="true"> 
    <thead> 
     <tr> 
      <th data-field="title">Title</th> 
      <th data-field="author">Author</th> 
      <th data-field="price">Price</th> 
      <th id="id_col" data-field="pk">ID</th> 
     </tr> 
    </thead> 
</table> 

<!-- need this script to refresh on keypress --> 
<script> 
$(function() { 
$("#table").bootstrapTable({ 
    onClickRow: function(row) { 
     window.location.href = "/books/get/" + row.pk; 
    } 
}); 
}); 
</script> 

引導-table.js片斷(可能是有益的)

if (this.options.search) { 
      html = []; 
      html.push(
       '<div class="pull-right search">', 
        sprintf('<input id="search" class="form-control" type="text" placeholder="%s">', 
         this.options.formatSearch()), 
       '</div>'); 

      this.$toolbar.append(html.join('')); 
      $search = this.$toolbar.find('.search input'); 
      $search.off('keyup').on('keyup', $.proxy(this.onSearch, this)); 
     } 
    }; 

回答

1

jQuery's .keypress()功能看看。有了這個,你可以做這樣的事情:

$("#table").keypress(function() { 
    $("#table").bootstrapTable({ 
     onClickRow: function(row) { 
      window.location.href = "/books/get/" + row.pk; 
     } 
    }); 
} 

它可能不是一個完美的解決方案,爲您的問題;您可能必須更改調用.keypress的元素。但是類似的東西會運行您在函數體中放置的任何代碼,無論何時出現按鍵事件,這就是您要查找的內容。