简体   繁体   English

Bootstrap表刷新

[英]Bootstrap Table refresh

I am using bootstrap table to display data from my MongoDB, using a mongoid query. 我使用bootstrap表来显示来自MongoDB的数据,使用mongoid查询。 I would like to refresh the table at an interval of 5 minutes. 我想以5分钟的间隔刷新桌子。 I've read the documentation, but being new to Javascript, I'm not sure how to accomplish this - whether to use an Ajax call or just a setTimeout() function, etc. 我已经阅读了文档,但是对Javascript不熟悉,我不知道如何实现这一点 - 无论是使用Ajax调用还是使用setTimeout()函数等。

This is my table code: 这是我的表格代码:

<table id="table" data-show-refresh="true" data-row-style="rowStyle" data-toggle="table" data-url="http://maccdx160121:4567/api/v1/currentsat*">
    <thead>
        <tr>

           <th data-field="initials">Initials</th>
            <th data-cell-style="cellStyle" data-field="sector">Sector</th>
            <th data-field="cjs">CJS</th>


        </tr>
    </thead>
 </table>

This is my Mongoid query, if it helps: 这是我的Mongoid查询,如果它有帮助:

get '/currentsat*' do

    #SatTransaction.where( current: true, :initials.ne => nil, :position.in => ["RDR", "SPVR", "OJI"] ).to_json
    SatTransaction.where( current: true, :shift_duration.ne => 0, ).and(SatTransaction.or({:position.in => ["SPVR", "RDR", "OJI"]},{sector: "BREAK"}).selector).to_json


    end



end

before do
  cache_control :no_cache
end

def with_captured_stdout
  old_stdout = $stdout
  $stdout = StringIO.new('', 'w')
  yield
  $stdout.string
ensure
  $stdout = old_stdout
end

Thanks for any help!! 谢谢你的帮助!!

I think you remove the table and recreate that: 我想你删除表并重新创建:

setInterval(function(){
    $('#table').remove();
    $('#Table_Parent').append(Table_Html);
}, 5000);

I think you need to do the both. 我想你需要做到这两点。 You need to get the data from the server using ajax and then reload it into the datatable. 您需要使用ajax从服务器获取数据,然后将其重新加载到数据表中。

Only refreshing the data table will just reload the data what you have in your html but you need to refresh because it will reload the chaged data. 只刷新数据表只会重新加载html中的数据,但需要刷新,因为它会重新加载chaged数据。

as @Farzin Kanzi code, inside the set time out make the ajax call and reload with server data 作为@Farzin Kanzi代码,在设置超时内部进行ajax调用并重新加载服务器数据

setInterval(function(){
    $.ajax(
    ...
    success(response) {
      Table_Html = resopnse
    }
   )
    $('#table').remove();
    $('#Table_Parent').append(Table_Html);
}, 5000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM