Parent / Child Table View Same Page?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Parent / Child Table View Same Page?

Post by dlee » 2022-03-20 21:27

What I would like is to have the table view of parent records and table view of child records on the same page. Then when you click on a parent record, the the list of records in the child table view would update to show the child records for the parent selected.

Is this possible?
If it is, how would I do accomplish this?

See attached file to see image of what I am after.

Thanks,
TD
Attachments
parent child table views same page.png
parent child table views same page.png (37.11 KiB) Viewed 2267 times

dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: Parent / Child Table View Same Page?

Post by dlee » 2022-03-21 15:12

Anyone ?

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1814
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Parent / Child Table View Same Page?

Post by jsetzer » 2022-03-21 16:34

Would be a lot of work, I'm afraid.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1814
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Parent / Child Table View Same Page?

Post by jsetzer » 2022-03-21 17:20

I have tried.

The problem is not embedding Detail View's Children-Tabs into Table View for the selected record, see screenrecording:

ezgif.com-gif-maker.gif
ezgif.com-gif-maker.gif (244.16 KiB) Viewed 2231 times

But for me the problem is passing over the Table View selection and filters into the child's details, for example when creating new children:

chrome_mjXTKhZfpO.png
chrome_mjXTKhZfpO.png (23.43 KiB) Viewed 2231 times
chrome_EuComGVQmS.png
chrome_EuComGVQmS.png (16.53 KiB) Viewed 2231 times

Right now I don't have any good solution. Hopefully others have.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: Parent / Child Table View Same Page?

Post by dlee » 2022-03-21 19:30

Thanks jsetzer for trying to help. Yes, hopefully someone has a solution.
TD

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Parent / Child Table View Same Page?

Post by pbottcher » 2022-03-21 20:15

Hi,

actually jsetzer shows how to do it. As I don't want to take the credit for others, I just add the trick to show the preselected reference.

Add to the DOM a hidden input field with name="SelectedID". Then, on the selection of the row from the top table, set the SelectedID as the data-id value. If you click on add new it should use that value to populated the selection.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: Parent / Child Table View Same Page?

Post by dlee » 2022-03-22 03:42

jsetzer can you explain how you did what you did in the gif you posted?

Thanks,
TD

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1814
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Parent / Child Table View Same Page?

Post by jsetzer » 2022-03-22 07:17

  1. In hooks/TABLENAME-tv.js I have added a <div/> using jQuery as a placeholder for the children tabs and named it TABLENAME-children
  2. Then I have added a button* to the first cell of each row of the table view.
    * Due to an agreement with Ahmed I must not show how I did this because I'm using a commercial product. Giving help based on commercial products is not welcomed in the free community area of this forum. Just add buttons to each row by using Javascript.
  3. On button-click I'm using .load-function of jQuery and fetch server-data from parent-children.php, which is the built-in script for retrieving children-tabs in the Detail View. I'm just re-using the detail-view code in the table view.
  4. Parameters for loading the children-tabs:
    • ParentTable: AppGini.currentTableName()
    • Operation: 'show-children'
    • SelectedID: YOURCURRENTPRIMARYKEYHERE
If there are problems, check the requests (payload) and responses in the network tab of your browser's developer tools.

Here is some code excerpt inside document.ready:

Code: Select all

 jQuery("<div/>").attr("id", `${AppGini.currentTableName()}-children`).addClass("children-tabs hidden").insertAfter(jQuery("table"));
 
// YOUR_FUNCTION_FOR_ADDINGBUTTONS

// YOUR_BUTTON_ONCLICK_HANDLER should execute:
function(pk) {
  jQuery(`#${AppGini.currentTableName()}-children`).load("parent-children.php", { ParentTable: AppGini.currentTableName(), Operation: 'show-children', SelectedID: pk }, function() { 
    jQuery(`#${AppGini.currentTableName()}-children`).hide().removeClass("hidden").fadeIn();
  };
};
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Parent / Child Table View Same Page?

Post by pbottcher » 2022-03-22 17:53

Hi,

here would be my proposal without an additional commercial product.

Code: Select all

$j(function(){ 
	const tablename=AppGini.currentTableName();
	$j('body').append('<input name="SelectedID" value="1" type="hidden">');
	$j('[data-table="'+tablename+'"]').parent('.row').append('<div id="'+tablename+'-children"></div>');
	btn='<button  type="button"  class="childtable btn btn-sm" title="Show child table"><i class="glyphicon glyphicon-search"></i></button>'
	$j('[data-table="'+tablename+'"] tbody tr td:first-child input').after(btn);
	$j('[data-table="'+tablename+'"] tbody tr td:first-child').attr('nowrap','');

	$j('.childtable').on('click',function() {
		id=$j(this).parents('tr').attr('data-id');
		$j('[name="SelectedID"]').val(id);
		post('parent-children.php', {ParentTable: tablename,SelectedID: id,Operation: 'show-children'},tablename+'-children');
	})
})
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

xbox2007
Veteran Member
Posts: 134
Joined: 2016-12-16 16:49

Re: Parent / Child Table View Same Page?

Post by xbox2007 » 2022-03-31 10:25

thanks a lot Mr. pböttcher

i already user your code and make some change NOW its look like that


1 (2).png
1 (2).png (49.51 KiB) Viewed 2043 times
2 (2).png
2 (2).png (59.17 KiB) Viewed 2043 times
3 (2).png
3 (2).png (87.96 KiB) Viewed 2043 times
thanks again

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Parent / Child Table View Same Page?

Post by pbottcher » 2022-04-01 14:23

Hi,

glad it works.

Maybe you can post the code you are using, so that might be also useful for others.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

xbox2007
Veteran Member
Posts: 134
Joined: 2016-12-16 16:49

Re: Parent / Child Table View Same Page?

Post by xbox2007 » 2022-04-01 22:18

this my code on table-tv.js

Code: Select all

$j(function(){
	$j('#NoFilter').after('<button class="btn btn-info btn-lg" type="button" onclick="myFunction()" id="Show_Child"><i class="glyphicon glyphicon-search"></i> Show Child </button>');
});

function myFunction() {
	const tablename=AppGini.currentTableName();
	$j('body').append('<input name="SelectedID" value="1" type="hidden">');
	$j('[data-table="'+tablename+'"]').parent('.row').append('<div id="'+tablename+'-children"></div>');
	btn='<button  type="button" id="btn"  class="childtable btn btn-primary btn-sm" title="Show child table"><i class="glyphicon glyphicon-search"></i></button>'
	$j('[data-table="'+tablename+'"] tbody tr td:first-child input').after(btn);
	$j('[data-table="'+tablename+'"] tbody tr td:first-child').attr('nowrap','');

	$j('.childtable').on('click',function() {
		id=$j(this).parents('tr').attr('data-id');
		$j('[name="SelectedID"]').val(id);
		post('parent-children.php', {ParentTable: tablename,SelectedID: id,Operation: 'show-children'},tablename+'-children');
	})
}

Post Reply