It would be awesome to have the ability to auto-refresh a table on a page. We have a table that a lot of our employees use to update customer records, and everybody has to constantly F5 to make sure they have the latest and greatest before updating old information.
Hey Andrew, what is the code for #view_1111?
Tks!
Voted!
An auto-refreshing page would be great! Ā ... particularly if there was a setting to control exactly how often it should refresh.
AGREEEDDDD!!!!!
Hi to all,
Good news!! Iāve got exactly what you want. Iāve coded a library called KTL that does this without a single line of code. All you have to do is add AUTOREFRESH=60 to the tableās title to get an update every minute.
If youāre interested, itās open-source (free). All you have to do is copy/paste the .js and .css files to your app in the Builder.
Get KTL here: https://github.com/cortexrd/Knack-Toolkit-Library
Enjoy!
Normand D.
Cortex R&D Inc.
Normand, any way of you posting the code here and is there away to implement your code without having to add āAUTOREFRESH=60ā in the tableās title?
Thank you in advance⦠JON
Hi,
Try below code.
$(document).on(āknack-view-render.view_157ā, function (event, view, records) {
AutoRefresh(āview_157ā,5000);
});
function AutoRefresh(viewId,ms)
{
setTimeout(function(){
AutoRefresh(viewId,ms);
Knack.views[viewId].model.data.fetch()
},ms);
}
Change view id and ms according to your requirements.
https://roberts.knack.com/farmers#test-field/
Regards,
Sunny Singla
ssingla1985@gmail.com
+919855089359
Hey Sunny, couldnāt get your code to work for me. Iām sure it something I did or didnāt do.
I changed view_157 on first 2 lines to my view (view_187) other than that, made no other changes.
Thanks as always⦠JON
Hello John,
Yes, you just need to make only those changes. Share your page url where you implemented it.
It works for me can you check it on my given url
Regards,
Sunny Singla
Iāll put the code in an example app and email you. I did open your url link above but wasnāt sure if your sample program was doing what was expecting. I was hoping for a solution to refresh a given tableās data every few seconds or minutes. It was hard to tell what your app was doing. I inputted some same data but thatās about it.
@Sunny_Singla your code works for me.
A tweak so itās easier to paste into JS inside a view render:
$(document).on(āknack-view-render.view_157ā, function (event, view, records) {
AutoRefresh(view.key,5000);
});
function AutoRefresh(viewId, ms) {
setTimeout(function() {
AutoRefresh(viewId, ms);
Knack.views[viewId].model.data.fetch()
}, ms);
}
Thanks @Sunny_Singla
Sunny, is there a solution that would stop the page from refreshing using your code when a user filters by search criteria.
Using your example app, when a user searches for āBMWā the table shows data containing āBMWā but then quickly refreshes and shows all table data. Any and all searches made are shown, but quickly refreshed within 5 seconds.
Also, is there a way for you to turn on āin line editingā for ātestmessagenameā field for your example app? Iād like to see if a user makes and submits changes this way if it will update on a 2nd open window within given time (ie 5 seconds). I couldnāt get changes made this way to reflect on 2nd open window in our app unless I pressed refresh on browser or F5.
Also, I created an āeditā link in our app that opened another page to edit given data. I couldnāt get updated/submitted data on 2nd open window unless we manually updated browser or pressed F5.
As always thank you⦠JON
Hi gentlemen,
I invite you to go see my new Youtube channel.
Cortex R&D Inc - Youtube Knack tutorials and more
Iāve just completed my first demo of the KTL. I think my auto refresh code adresses part of your problem since it pauses refreshing as soon and as long as you set the focus on a Search input field, and maintains the results afterwards.
Give it a try and let me know if it helps.
Norm
Hi Sunny and Brad - I have tried both of your proposed solutions without success. Normand, your code looks interesting and addresses the issue indicated about search results refreshing, but Iām not prepared to implement everything at once nor do I want to spend time turning off functions of the code, perhaps one day!
Sunny and Brad, is there something Im missing in my code? I changed the view to my table view (857) but no luck. Any help is greatly appreciate!
$(document).on(āknack-view-render.view_857ā, function (event, view, records) {
AutoRefresh(āview_857ā,5000);
});
function AutoRefresh(viewId,ms)
{
setTimeout(function(){
AutoRefresh(viewId,ms);
Knack.views[viewId].model.data.fetch()
},ms);
}
Hello Ryan,
Just see your message. And I donāt think there is any issue in this code.
May be some other issue. If possible share your page url so we can check.
Regards,
Sunny Singla
ssingla1985@gmail.com
+919855089359
Hi RyanL,
Iāve added a new template file for those like you whoād like to test the KTL with everything turned off, and enabling only the desired features one by one.
See the updated documentation here.
Let me know if you have questions or concerns.
Norm
Hey Normand,
Your KTL is pretty amazing. I havenāt used it personally but I am digging through your code and borrowing some features. I do have a couple of questions. I noticed in this thread that folks suggest using a five second interval along with Knack.views[view.key].model.data.fetch(). Meanwhile your code is 60 seconds and you use Knack.views[view.key].model.fetch().
I am curious if you noticed a difference between data and model refresh?
Also curious why you defaulted to 60 seconds? I tried the 5 second approach but I am worried if the amount of calls to the server could overload it. The server for one of my apps went down last night after introducing the 5 second interval and that was the only change I made.
Hi Robert,
Thanks for the nice comments Glad you like it.
About your questions:
- fetch()
When I use Knack.views[āview_1ā].model.data.fetch(); I see no updates in the view. As if it does nothing.
But when I use Knack.views[āview_1ā].model.fetch(); I so see the updates.
Note that if you use the complete function ktl.views.refreshView(āview_1ā), it will work with ANY view types, not just grids. Even forms will refresh!
- My default of 60 seconds was just an arbitrary choice, that I thought would make sense - not too slow nor too fast. I decided to enforce a lower limit of 5 seconds to avoid overloading the āalready-busy-enoughā servers
Of course, 5 seconds is quite fast for large tables with lots of rows and fields. But I can tell you that I use several grids with 10 seconds refresh where they have a single row and 5 fields - without problems.
It should not cause a Knack servers crash per say, but I noticed that the refresh function sometimes encounters errors 500, 502, etc. In such cases, the app needs to be reloaded manually (F5 or Ctrl+R) most of the time, unless it was caught by your code or the KTL and handled appropriately.
These unrecoverable errors are currently causing big problems to my client, where they have dozens of unattended dashboards across their industrial plant to monitor the production status.
I have developed a custom solution involving a NodeJS watchdog (they use Linux devices with Chromium), talking to the Knack App and force a refresh in case of a crash. Works well.
Norm