Page 1 of 1

How to Display ViewPage in Modal Dialog on Row Click (v2019)

Posted: Mon Feb 11, 2019 1:02 pm
by mobhar

Sometimes you need to display the View Page in Modal Dialog by simply clicking on the row in table of the List Page. In other words, you don't want to display it by only clicking on the "magnifying glass" icon as you did until now. This is very useful if you want to give your end-users the ability to display the View Page in Modal Dialog quickly and easily, moreover if you enable UseDropDownButton and UseButtonGroup options in order to group and display several buttons in each row of the table. You will save two clicks event for this, of course.

So here is the mixing PHP + jQuery code below that you can use. Simply put it in "Startup Script" of the "List Page". In this example, we use the "models" table from the demo project. Make sure also you have already enabled "Modal dialog" under "Table" setup -> "Table Options" -> "View Page" that belongs to the "models" table before regenerating all the script files.

<?php if (Security()->canView()) { // don't forget this for security ?>
$(document).ready(function() {
$('#tbl_modelslist tr').click(function() { // click event for table id and row selector; adjust it to your table id!
var view_modal = $(this).find("a.ew-row-link.ew-view").attr("onclick"); // get the modal dialog javascript syntax
var view_url = view_modal.substring(view_modal.lastIndexOf(":'") + 2, view_modal.lastIndexOf("'")); // get the url that belongs to each row
ew.modalDialogShow({lnk:this, url: view_url}); // display the View Page in modal dialog
});
});
<?php } ?>

The limitation of this code:
If you enable "UseDropDownButton" and "UseButtonGroup" options, then when you click on the dropdown button in each row, that code above will always be executed, so that code needs to be improved in order to exclude the click event of dropdown button in each row of the table. Not sure we can do this, any feedback or improvement are welcome.

Enjoy the code, everyone! :-)


Re: How to Display ViewPage in Modal Dialog on Row Click (v2

Posted: Sun May 19, 2019 10:58 pm
by milver.silva

And how to open the view page without modal?


Re: How to Display ViewPage in Modal Dialog on Row Click (v2

Posted: Mon May 20, 2019 6:07 pm
by mobhar

To display the normal View Page (without Modal dialog), simply try this instead:

<?php if (Security()->canView()) { // don't forget this for security ?>
$(document).ready(function() {
$('#tbl_modelslist tr').click(function() { // click event for table id and row selector; adjust it to your table id!
var view_page = $(this).find("a.ew-row-link.ew-view").attr("href"); // get the href
window.location.href = view_page; // open the view page
});
});
<?php } ?>


Re: How to Display ViewPage in Modal Dialog on Row Click (v2

Posted: Tue May 21, 2019 9:29 pm
by milver.silva

Thank you! :-)


Re: How to Display ViewPage in Modal Dialog on Row Click (v2

Posted: Wed May 22, 2019 12:06 am
by andyrav

Thanks,
how would you modify this so it can be added at global level?
cheers


Re: How to Display ViewPage in Modal Dialog on Row Click (v2

Posted: Wed May 22, 2019 3:35 pm
by mobhar

Simply change this code:
'#tbl_modelslist tr'

to:
'.table.ew-table tr'

and move all those code into "Startup Script" under "Client Scripts" -> "Global" -> "Pages with header/footer".


Re: How to Display ViewPage in Modal Dialog on Row Click (v2

Posted: Tue Jun 11, 2019 7:15 am
by sangnandar

mobhar wrote:
The limitation of this code:
If you enable "UseDropDownButton" and "UseButtonGroup" options, then when you click
on the dropdown button in each row, that code above will always be executed,

You can cancel <tr onclick> with <td onclick>. Use: event.stopPropagation()


Re: How to Display ViewPage in Modal Dialog on Row Click (v2

Posted: Thu Jun 13, 2019 5:51 am
by fuad

useful,thanks


Re: How to Display ViewPage in Modal Dialog on Row Click (v2

Posted: Fri Jun 21, 2019 6:22 pm
by Niijimasama

mobhar wrote:
Simply change this code:
'#tbl_modelslist tr'

to:
'.table.ew-table tr'

and move all those code into "Startup Script" under "Client
Scripts" -> "Global" -> "Pages with header/footer".

Brilliant and Thank you.


Re: How to Display ViewPage in Modal Dialog on Row Click (v2

Posted: Fri Jun 21, 2019 7:27 pm
by Niijimasama

mobhar wrote:
To display the normal View Page (without Modal dialog), simply try this instead:

<?php if (Security()->canView()) { // don't forget this for security ?>
$(document).ready(function() {
$('#tbl_modelslist tr').click(function() { // click event for table id and row
selector; adjust it to your table id!
var view_page =
$(this).find("a.ew-row-link.ew-view").attr("href"); // get the
href
window.location.href = view_page; // open the view page
});
});
<?php } ?>

Hi.

Thank you again.

As I also needed to enable edit, I added the double click option as below:

<?php
if (Security()->canEdit()) { ?>
$(document).ready(function() {
$('#tbl_shop_infolist tr').dblclick(function() {
//$('.table.ew-table tr').click(function() {
var edit_page = $(this).find("a.ew-row-link.ew-edit").attr("href");
window.location.href = edit_page;
});
});
<?php } ?>


Re: How to Display ViewPage in Modal Dialog on Row Click (v2

Posted: Tue Jul 09, 2019 4:52 am
by smpsrllc

//v2018 View

<?php if (Security()->canView()) { // don't forget this for security ?>
$(document).ready(function() {
$('#tbl_modelslist tr').click(function() { // click event for table id and row
selector; adjust it to your table id!
var view_page =
$(this).find("a.ewRowLink.ewView").attr("href"); // get the
href
window.location.href = view_page; // open the view page
});
});
<?php } ?>

//v2018 Edit

<?php
if (Security()->canEdit()) { ?>
$(document).ready(function() {
$('#tbl_shop_infolist tr').dblclick(function() {
//$('.table.ew-table tr').click(function() {
var edit_page = $(this).find("a.ewRowLink.ewEdit").attr("href");
window.location.href = edit_page;
});
});
<?php } ?>


Re: How to Display ViewPage in Modal Dialog on Row Click (v2

Posted: Tue Feb 18, 2020 6:37 pm
by amiens80

hi,

your solution is great. it works fine in phpmaker 2020.0.11.

very great idea my lord!

one question : to complete the behaviour, did you manage to add the "cursor click icon" on the mouse cursor to help the user to understand he can click there ? (mouse over icon must change when an action is available by clicking).
i guess it might me somewhere in the template css....

Have a great day


Re: How to Display ViewPage in Modal Dialog on Row Click (v2

Posted: Fri Apr 03, 2020 1:49 am
by hemin
how to make this work with preview row ?

Re: How to Display ViewPage in Modal Dialog on Row Click (v2

Posted: Tue Apr 07, 2020 12:15 pm
by mobhar
So here is the latest updated version that also handling for Preview row (using Preview extension; only for the registered users), and make sure to put it in "Startup Script" of "List Page" that belongs to "Master Table".

<?php if (Security()->canEdit()) { // don't forget this for security ?>
$(".table.ew-table tr").dblclick(function(e) { // double click to open Edit Page in Modal Dialog
// make sure to exclude the following condition
if (!$(e.target).hasClass('btn') && !$(e.target).hasClass('ew-preview-row-btn') && !$(e.target).hasClass('custom-control-label')) {
var edit_modal = $(this).find("a.ew-row-link.ew-edit").attr("onclick"); // get the modal dialog javascript syntax
var edit_url = edit_modal.substring(edit_modal.lastIndexOf(":'") + 2, edit_modal.lastIndexOf("'")); // get the url that belongs to each row
ew.modalDialogShow({lnk:this, url: edit_url, caption: '<?php echo Language()->phrase("Edit"); ?>', btn: 'SaveBtn'}); // display the Edit Page in modal dialog
}
});

$(document).on("preview", function(e, args) { // for preview row
args.$tabpane.find("tr").dblclick(function (e) { // double click
// make sure to exclude the following condition
if (!$(e.target).hasClass('btn') && !$(e.target).hasClass('ew-preview-row-btn') && !$(e.target).hasClass('custom-control-label')) {
var edit_modal = $(this).find("a.ew-row-link.ew-edit").attr("onclick"); // get the modal dialog javascript syntax
var edit_url = edit_modal.substring(edit_modal.lastIndexOf(":'") + 2, edit_modal.lastIndexOf("'")); // get the url that belongs to each row
ew.modalDialogShow({lnk:this, url: edit_url, caption: '<?php echo Language()->phrase("Edit"); ?>', btn: 'SaveBtn'}); // display the Edit Page in modal dialog
}
});
});
<?php } ?>

<?php if (Security()->canView()) { // don't forget this for security ?>
$(".table.ew-table tr").click(function(e) { // single click to open View Page in Modal Dialog
// make sure to exclude the following condition
if (!$(e.target).hasClass('btn') && !$(e.target).hasClass('ew-preview-row-btn') && !$(e.target).hasClass('custom-control-label')) {
var view_modal = $(this).find("a.ew-row-link.ew-view").attr("onclick"); // get the modal dialog javascript syntax
var view_url = view_modal.substring(view_modal.lastIndexOf(":'") + 2, view_modal.lastIndexOf("'")); // get the url that belongs to each row
ew.modalDialogShow({lnk:this, url: view_url, caption: '<?php echo Language()->phrase("View"); ?>', btn: null}); // display the View Page in modal dialog
}
});

$(document).on("preview", function(e, args) { // for preview row
args.$tabpane.find("tr").click(function (e) { // single click
// make sure to exclude the following condition
if (!$(e.target).hasClass('btn') && !$(e.target).hasClass('ew-preview-row-btn') && !$(e.target).hasClass('custom-control-label')) {
var view_modal = $(this).find("a.ew-row-link.ew-view").attr("onclick"); // get the modal dialog javascript syntax
var view_url = view_modal.substring(view_modal.lastIndexOf(":'") + 2, view_modal.lastIndexOf("'")); // get the url that belongs to each row
ew.modalDialogShow({lnk:this, url: view_url, caption: '<?php echo Language()->phrase("View"); ?>', btn: null}); // display the View Page in modal dialog
}
});
});
<?php } ?>