简体   繁体   English

用于刷新页面和/或telerik网格的JavaScript代码

[英]JavaScript code to refresh page and or telerik grid

I need some kind of code which will refresh the page every 5min and if not the page then just the Telerik grid displayed on it since that's all that's rly needed. 我需要某种代码,每5分钟刷新一次页面,如果没有页面,那么只显示Telerik网格,因为这就是所需要的。

Only other thing would be if it was after 5min of no activity on the page if possible but it's not core feature. 只有在可能的情况下,如果在页面上没有活动5分钟后才会出现其他事情,但这不是核心功能。

One possibility is to use a meta refresh tag: 一种可能性是使用元刷新标记:

<meta http-equiv="refresh" content="300" />

Another possibility is to use the window.setInterval method to send periodic AJAX requests to a controller action and update the DOM: 另一种可能性是使用window.setInterval方法将定期AJAX请求发送到控制器操作并更新DOM:

window.setInterval(function() {
    // Send an AJAX request to a controller action which will
    // return a partial with the grid and update the DOM
    $.ajax({
        url: '/grid',
        success: function(result) {
            $('#someGridContainer').html(result);
        }
    });
}, 300000);

And to implement the idle functionality you could use the jquery idle plugin . 要实现空闲功能,您可以使用jquery idle插件

keep it simple, call refreshGrid() function when you need to refresh grid. 保持简单,在需要刷新网格时调用refreshGrid()函数。

function refreshGrid() {
    if ($(".t-grid .t-refresh").exists()) {
        $(".t-grid .t-refresh").trigger('click');
    }
}

/*return true if does selected element exist.*/
(function ($) {
    $.fn.exists = function () { return jQuery(this).length > 0; }
})(jQuery);
    setTimeout(function(){
      window.location.reload();
   },300000);

If your grid is set up for ajax refreshes, then you can use something like 如果您的网格设置为ajax刷新,那么您可以使用类似的东西

    <script type="text/javascript">
        $(function() {
            setInterval(function() {
                $('#GridName').data('tGrid').ajaxRequest(); 
            }, 300000);
        }); 
    </script>   

For Server Bindings Telerik Grid Just need to do the following Thing..... Just use and cheers 对于服务器绑定Telerik Grid只需要执行以下操作.....只需使用和欢呼

After any event you can call this 任何事件发生后你都可以打电话

   var href = $('.t-refresh').attr('href');
    window.location.href = href;

If you are using Ajax or Webservice binding on the Telerik Grid, you can call the rebind() method on the grid object. 如果在Telerik Grid上使用Ajax或Webservice绑定,则可以在网格对象上调用rebind()方法。 That will force it to call the Select method of the binding again to get the latest data. 这将迫使它再次调用绑定的Select方法以获取最新数据。

If you combine the rebind() call with Darin's answer of using the SetInterval method, it should give you what you are after. 如果你将rebind()调用与Darin使用SetInterval方法的答案结合起来,它应该会给你你想要的东西。

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

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