How do we insert above or below a particular row in grid?

We want to allow the user to add a row below the existing row conditionally, from click of a custom button, instead of ‘Insert Above’/‘Insert Below’.

cur_frm.add_child adds a row at the bottom. We want the new row right below the current row and take care of indexing also.

Any pointers?

Thanks
Krithi

  • copy the child table docs into a variable
  • clear the original child table
  • populate the child table as you desire
  • refresh when done

I was looking at using the same event that is there in the core, to insert_above or insert_below. Wont that be possible?

Krithi

Good idea. That will work

I couldn’t find any explicit function to do that, need help there.

Even if conditionally you are able to add a row just below, the grid rows are draggable, so anyone can add any row and then drag it above or so. Wouldn’t that kinda kill the whole conditionality ?

Where is it draggable?

Take your pointer between the checkbox and the row no. , click on it and drag it up or down. The row number will adjust accordingly too

@Zlash65 drag to reorder doesn’t work for me. I am new to ERPNext and i thought this was not supported.
Is it just me? is there anyone else for whom it doesn’t work?

drag-to-move
Seems to be working for me ? Are we talking about something else perhaps ? This feature has been there since long though

1 Like

Doesn’t work for me either. Is this only in Doctype or all grids?

Hey,
Just figured out… it doesn’t work on chrome-ubuntu 16.04…
But it works on chrome-windows and firefox-ubuntu …

@krithi_ramani @Zlash65 can you please mentions your Browser and OS… so that we can confirm the issue is similar.

I don’t think thats the case @karthikeyan5 Prior to mac I had ubuntu and this used to work then too.
@krithi_ramani Its for all grids

when is “then”?
I guess a lot must have changed from “then” and “now”… Because chrome and frappe has had two major versions changes in the last 4 months…
can somebody else please confirm the issue exists in current versions?

As @Zlash65 claims worked for me provided this is current by your standards @karthikeyan5

frappe@erpnext:~/frappe-bench$ bench version
erpnext 9.2.23
frappe 9.2.24

trusty tahr aka 14.04 lts

frappe@erpnext:~/frappe-bench$ uname -a
Linux erpnext 3.13.0-79-generic #123-Ubuntu SMP Fri Feb 19 14:28:32 UTC 2016 i686 i686 i686 GNU/Linux

Chrome Version 60.0.3112.78 (Official Build) (64-bit)

Am on

erpnext 8.0.44
frappe 8.0.64

Chrome - Version 60.0.3112.113 (Official Build) (64-bit)

Linux ecapv7devremote 4.4.0-93-generic #116-Ubuntu SMP Fri Aug 11 21:17:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

@Zlash65 I remember seeing this feature only in ‘Customize form’ in v6, but not after that.

Ok, In V9.2 , am able to drag the rows both in firefox and Chrome (Ubuntu). I should now rethink the design.

Thanks @Zlash65

Found it. On button click,

var grid_row = cur_frm.open_grid_row();
grid_row.insert(true, true);

would insert a row right below the current row and set the focus in the new row.

4 Likes