Auto-Refreshing Tables

Code wasn’t working for me. ChatGPT suggested the following and it works now:

$(document).on(‘knack-view-render.view_157’, function (event, view, records) {
AutoRefresh(view.key, 5000);
});

function AutoRefresh(viewId, ms) {
setTimeout(function() {
Knack.views[viewId].model.fetch();
AutoRefresh(viewId, ms);
}, ms);
}


Use the following to refresh multiple views:

var autoRefreshViews = [‘view_1’, ‘view_2’, ‘view_3’]; // Replace with your view keys

$(document).on(‘knack-view-render.any’, function (event, view) {
if (autoRefreshViews.includes(view.key)) {
AutoRefresh(view.key, 5000);
}
});

function AutoRefresh(viewId, ms) {
setTimeout(function() {
Knack.views[viewId].model.fetch();
AutoRefresh(viewId, ms);
}, ms);
}

Hi GSergeant,

What is the difference? Look like chatgpt copy the same code and adds some extra …

Sometimes when we copy a single quote replace it with which causes javascript to stop working.

Regards
Sunny Singla
ssingla1985@gmail.com
+919855089359