How can i implement nested Table's in ERPNext

If you guys can atleast tell me , how can i pass the current docname to the Grid → wn.ui.form.Grid

i will be able to solve this issue. however i cannot use the this.frm.docname , as it will always give me the FORM docname, but instead i want to know the parent grid docname for the child grid.

I have reached here so far, but my main issue over here is, if i add a new child row for a parent, then it gets added to all the other parent rows as well.

Thanks