Page 1 of 1

How to open DV in modal from TV

Posted: 2020-10-19 14:18
by ronwill
Hi,

I would like to be able to select a record in Table view that will open the Detailed view in a modal (not separate page).

It should work similar to like when you click on <%%PLINK(name)%%><%%ADDNEW(name)%%> in a detail view whereby the record opens an editable (if permitted) pop up modal showing just the form contents (No header, menu, footer).

But in this case it should work by selecting the record "td" in table view to open the corresponding DV record in a modal.

Any help appreciated please.

Ron

Re: How to open DV in modal from TV

Posted: 2020-10-30 16:34
by ronwill
Anyone?

Re: How to open DV in modal from TV

Posted: 2020-10-30 16:40
by jsetzer
Maybe you should have a look at modal_window function. There is a URL parameter in options. The url should be something like TABLENAME_view.php?SelectedID=1234567. I think you will also need the Embedded=1 parameter. But actually I did not test and don't know for sure, if this idea works for your requirement.

Re: How to open DV in modal from TV

Posted: 2020-10-30 17:10
by jsetzer
Addendum:
I have tested it, and with the following script you can open a modal page with a detail view in it.

Code: Select all

let options = {
  url: AppGini.currentTableName() + "_view.php?SelectedID=" + id + "&Embedded=1",
  size: 'full',
  footer: [ { label: "Close" } ]
};
modal_window(options);
chrome_TdDWnhpop8.png
chrome_TdDWnhpop8.png (21.48 KiB) Viewed 5312 times

Attention

There are still some challenges with the margins and the proper handling of errors and redirections. I'm afraid that a 100% clean and "hooks-only" solution might not exist at all or/and would cause a lot of additional work.

Re: How to open DV in modal from TV

Posted: 2020-10-30 17:33
by ronwill
Thanks Jan,

I give this a go.....

Ron

Re: How to open DV in modal from TV

Posted: 2020-11-03 16:38
by ronwill
Hi Jan,

Works as hoped for/required only problem is opens same number of modals as number of records in a table, not just selected ID
Been playing with it but can't find way round it!!

Cheers,
Ron

Re: How to open DV in modal from TV

Posted: 2020-11-03 19:27
by jsetzer
Hi Ron,
I cannot see your code, so it's hard for me to say what went wrong.

I don't know what you mean by "selected ID", because in TV there may be none selected, one or many.

My code contains the variable "id" and you have to set it before that function call.

Code: Select all

let id = 1; // <-- you have to find out the id (primary key) of the record you want to open
let options = {
  url: AppGini.currentTableName() + "_view.php?SelectedID=" + id + "&Embedded=1",
  size: 'full',
  footer: [ { label: "Close" } ]
};
modal_window(options);

Re: How to open DV in modal from TV

Posted: 2020-11-03 22:23
by ronwill
Hi Jan,

I've been putting below code in my filename.DV template file:

Code: Select all

<script>	
				let options = {
								url: AppGini.currentTableName() + "_view.php" + "?SelectedID=<%%VALUE(id)%%>" + "&Embedded=1",
								size: 'full',
								footer: [ { label: "Close" } ]
				};
								modal_window(options);
</script>		
It does exactly what I was after, i.e. when i select any record from table list it opens the selected record in a modal. BUT it opens 3 modals (embedded inside each other, all showing the selected record, I have 3 records in my table list.
AG file is set for enable detail view and show detail view as separate page.

I can upload a demo on my server if that helps!!?
Cheers, Ron

Re: How to open DV in modal from TV

Posted: 2020-11-04 05:35
by jsetzer
Hi,

(1) your question was about opening up a modal DV from within a Table View (TV). So the code for opening up should be placed in TABLENAME-tv.js, not in detail view.

(2) If you put the code without just inside the script file it will be executed on load and not on selection of any record.

You need a button or link which calls a function. That funtion has to find the selected id, build the url and then open up the modal.

Re: How to open DV in modal from TV

Posted: 2020-11-05 00:09
by ronwill
Hi Jan,

I'm still getting same result (multi modals). the only way I found to prevent it is by following code in table-TV.js

Code: Select all

$j(function(){

//catch the behavior of clicking on any td , prevent it's defulat , the preventDefault dosn't work try to test it and then put your modal of pop up code in the file
$j("td a").click(function(event){

event.preventDefault();


//put your modal or popup behaviour here
let id = 2; // <-- you have to find out the id (primary key) of the record you want to open
modal_window({
	url: AppGini.currentTableName() + "_view.php?SelectedID=" + id + "&Embedded=1",
	close: function(){
		//do things on close of modal;
	},
	size: 'full',
	title: 'My title'
});



})

})	
This works but can't find a way to change line: let id = 2; to find the primary key of the record (i.e. id=1, id=2, etc.)
Cheers, Ron

Re: How to open DV in modal from TV

Posted: 2020-11-06 07:29
by jsetzer
Inside your click event handler:

Code: Select all

var id = $j(this).closest('tr[data-id]').attr('data-id');
(Not tested)

Re: How to open DV in modal from TV

Posted: 2020-11-06 13:04
by ronwill
Hi Jan,

PERFECT! Thank you so much for your help and guidance, I'd never have got there by myself.
Your solution works just how I wanted the end result to be like and allows me to move forward with my project - you saved the day, I as many here will continue to be thankful for all the help and assistance you provide through this forum and with: AppGiniHelper + Inline Detail view (Highly recommend these to everyone).

Cheers,
Ron

Re: How to open DV in modal from TV

Posted: 2020-11-06 13:34
by jsetzer
Thank you, Ron, for the very kind and appreciative words!

Re: How to open DV in modal from TV

Posted: 2020-11-15 15:32
by ronwill
Hi Jan,

I just upgraded to AG 5.92 and this solution no longer works?
Any idea what/where/why the upgrade stops this from working?

Cheers, Ron

Re: How to open DV in modal from TV

Posted: 2020-11-15 16:07
by jsetzer
should still work. Can you please tell, which part does not work any longer:
  • click-event on td
  • getting the id
  • opening the modal
  • other?
Are there any warning or errors in console?

Re: How to open DV in modal from TV

Posted: 2020-11-15 16:16
by ronwill
Hi Jan,

Sorry, I found the problem:

I had my header.php as read only. Once I removed it, saved as updated by latest version, reapplied my small mods, re-saved again, everything worked as should again.

Best regards Ron

Re: How to open DV in modal from TV

Posted: 2020-11-15 16:22
by jsetzer
Great! I'm glad it still works in latest version.

Best,
Jan