Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Only other thing would be if it was after 5min of no activity on the page if possible but it's not core feature.

like image 889
Myzifer Avatar asked Aug 25 '26 20:08

Myzifer


2 Answers

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(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.

like image 124
Darin Dimitrov Avatar answered Aug 27 '26 11:08

Darin Dimitrov


keep it simple, call refreshGrid() function when you need to refresh grid.

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);
like image 43
Nuri YILMAZ Avatar answered Aug 27 '26 10:08

Nuri YILMAZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!