Page 1 of 1

Refreshing table rows with Ajax (v2020)

Posted: Fri Nov 22, 2019 5:12 pm
by Adam

Place in Client Scripts > Global > Pages with header/footer > Global Code)

function refreshTable(delay = 10000, previewCheck = true) { // Refresh period ... 1000 = 1 second
	tableRefresh = setInterval(function() {
		if (previewCheck && $('.ew-preview-row-btn.icon-collapse').length > 0)
			return;
		$('.ew-preview-row-btn.icon-collapse').trigger('click');
		$('table.ew-table > tbody').load(location.href + ' table.ew-table > tbody tr', function() {
			$(this).find('tr:even').removeClass('ew-table-alt-row').addClass('ew-table-row');
			$(this).find('tr:odd').removeClass('ew-table-row').addClass('ew-table-alt-row');
			$('.ew-preview-row-btn').click(ew.showDetails);
			$('div.ew-preview [data-toggle="tab"]').on('show.bs.tab', ew.tabShow);
			$('div.popover').hide();
			ew.initTooltips();
		});
	}, delay);
}

Then place one of these variants in the relevant Client Scripts > Table Specific > List Page > Startup Script event(s):

refreshTable(); // this variant triggers refreshes every "default delay" (10 in the above code) seconds, but ONLY if no preview panes are visible
refreshTable(20000); // this variant triggers refreshes every 20 seconds, but ONLY if no preview panes are visible
refreshTable(30000, false); // this variant triggers refreshes every 30 seconds - regardless of preview pane visibility

Re: Refreshing table rows with Ajax

Posted: Fri Dec 13, 2019 8:51 am
by sticcino

was on a listview that refreshes.... selected "view" when a refresh is taking place on the listview in the background it is affecting the modal dialog display...
on this particular view form its a master /detail view, the grid/rows on the modal dialog form displayed columns that were part of the background listview form.
so the grid had its own columns 4 in this case --- and then next to those 4 were an additional 5 columns that were appended to the end of the grid -- which these 5 columns were part of the list-view in the background/main page.

not sure if this is fixable, can u detect when a modal dialog is popped up and suspend the refreshing of the table ?


Re: Refreshing table rows with Ajax

Posted: Sat Dec 14, 2019 1:42 am
by Adam

Actually, this is probably better as modal dialogs should always be avoided...

if ((previewCheck && $('.ew-preview-row-btn.icon-collapse').length > 0) || $('.modal.show').length > 0)


Re: Refreshing table rows with Ajax

Posted: Sun Jan 05, 2020 10:30 pm
by gigakun

Thanks Adam. Script works great. But I'm encountering a bug on pages that use "multiple detail tables". When it refreshes, my detail tables are completely messed up visually. I dunno how to describe it. Can anyone else confirm? Thanks.


Re: Refreshing table rows with Ajax

Posted: Mon Jan 06, 2020 10:34 pm
by sticcino

did you apply the fixes noted in this thread.


Re: Refreshing table rows with Ajax

Posted: Tue Jan 07, 2020 12:35 am
by gigakun

Yup the script is currently

function refreshTable(delay = 10000, previewCheck = true) { // Refresh period ... 1000 = 1 second
tableRefresh = setInterval(function() {
if ((previewCheck && $('.ew-preview-row-btn.icon-collapse').length > 0) || $('.modal.show').length > 0)
return;
$('.ew-preview-row-btn.icon-collapse').trigger('click');
$('table.ew-table > tbody').load(location.href + ' table.ew-table > tbody tr', function() {
$(this).find('tr:even').removeClass('ew-table-alt-row').addClass('ew-table-row');
$(this).find('tr:odd').removeClass('ew-table-row').addClass('ew-table-alt-row');
$('.ew-preview-row-btn').click(ew.showDetails);
$('div.ew-preview [data-toggle="tab"]').on('show.bs.tab', ew.tabShow);
$('div.popover').hide();
ew.initTooltips();
});
}, delay);
}

and

refreshTable(60000, false);

works fine on a regular list, and table detail list. my problem sounds similar to your last problem but it happens a master table with "multiple details tables" enabled.

it happens in the demo project as well. In the demo project copy the script to the global section as usual and the refresh call can go in the list page startup script section of "orderdetails" or/and "order details extended". Personally I put the call in the global startup so that all pages will refresh but for the sake of debugging we can leave it a single table.

Generate and navigate to Other Tables > Orders. Go to the master detail view of an order. You'll see the two tabs (detail tables). Scroll to the bottom of the table, wait for the refresh and see what happens.

Thanks.


Re: Refreshing table rows with Ajax

Posted: Thu Feb 06, 2020 8:55 am
by sticcino

Hi Adam,

  • is it possible to modify the code -- create another function (eg: refreshPreviewTable) that will update a preview listview?

i have a client master -> documents preview/sub-form and on that form the user can archive/zip the displayed documents, I use an ajax call to initiate the zipping function and create a table entry, i'd love for the grid to display the new record after the ajax call returns. I think you disabled this due to issues with master/detail links

  • if listview is in grid-add or grid-edit mode a refresh occurs and wipes any data on the form....

  • is there a way to hide the page load progress
    using "Adams" table refresh code, and don't want the load progress to be displayed while the refresh is happening (v2020)


Re: progress bar - hide

Posted: Thu Mar 19, 2020 8:37 am
by mobhar

Re: Refreshing table rows with Ajax

Posted: Mon Mar 23, 2020 6:05 am
by sticcino
thanks!, is there a jquery/Js method to do this ?

Re: Refreshing table rows with Ajax

Posted: Mon May 04, 2020 6:11 am
by sticcino

have a client view form that also displays 2 detail-forms

when the client record is viewed as:
clientsview.php?showdetail=client_docs,clients_notes&id=123456

it appears that the refreshTable() is executed on the two detail forms... when this happens, the rows from both forms are merged onto each detail tab

is it possible to suppress table refresh on a "view form" ?


Re: Refreshing table rows with Ajax

Posted: Wed May 06, 2020 6:02 am
by Adam
Update this line...

if (previewCheck && $('.ew-preview-row-btn.icon-collapse').length > 0)

...and simply add to the list of elements to avoid...

if (previewCheck && ($('.ew-preview-row-btn.icon-collapse').length > 0 || $('some_other_element').length > 0 || etc...)

Re: Refreshing table rows with Ajax

Posted: Mon May 25, 2020 4:39 am
by sticcino
added the follow to suppress refreshes if multi-tabs/detail-pages have been added to a view

|| $('.ew-detail-pages').length > 0

Re: Refreshing table rows with Ajax

Posted: Wed Apr 07, 2021 9:16 pm
by bpmsolutions

This works very well in list pages.
Can this be modified to work on dashboard report?
I have a dashboard form with multiple summary reports. Function is working, but as a result data on the summary reports is messed-up.


Re: Refreshing table rows with Ajax

Posted: Wed Apr 21, 2021 9:15 pm
by Adam

Can't think of a reason why it couldn't be made to work, but it's something you'll need to experiment with.

I'm not sure what you mean by "but as a result data on the summary reports is messed-up", but it may be the case that you have to replace charts / reports individually.

You may also need to trigger some JS to reinitalise events - you'll see that being done in my list page example, but I assume the events will be different.


Re: Refreshing table rows with Ajax

Posted: Mon Dec 20, 2021 3:19 am
by begin2know

Added to suppress refresh while on grid add or grid edit page

|| $('.ew-grid-add-edit').length > 0


Re: Refreshing table rows with Ajax

Posted: Mon Jul 18, 2022 8:02 pm
by sticcino

Hi Adam,

with the ability to hide columns now..., if you have hidden columns, the table row refresh functionality displays the hidden column data as well, with the headers being blank - if that makes sense. Looks like its refreshing all the columns and should not re-display hidden columns on the refresh...


Re: Refreshing table rows with Ajax

Posted: Fri Aug 05, 2022 10:03 am
by Adam

It's been a very long time since I shared that code - it may (or may not) be possible to correct the issue you describe, but you'll need to do some experimenting to confirm that.

If you manage to find a solution then please post it here to assist others.


Re: Refreshing table rows with Ajax

Posted: Tue Sep 27, 2022 1:55 am
by MahatmaGuru

Hi Adam - after refresh all hover over functions cease to work i.e. the mouseover no longer highlights a field.
Did you also experience this?


Re: Refreshing table rows with Ajax (v2020)

Posted: Mon Oct 24, 2022 6:33 am
by Adam

I haven't used the code for a long time, but that was an initial issue - I'm pretty sure that the ew.initTooltips(); line fixed it, but perhaps it's no longer effective.