Add row to top of data grid without refreshing

When I am deleting row from datagrid it works without refresh, instant:

def order_delete(self, **event_args):
    
  self.item.delete()
  self.remove_from_parent()

Is there any opposite to this when I want to add row or it is not possible ?

I would like to add row at the top of datagrid, but without refreshing whole datagrid.

If you want to add to a row in the repeating panel, you could modify its items.

Try inspecting self.repeating_panel_1.items. It is a list of dictionaries/rows.

If you want to add a data row panel, could you use add_component and rearrange the full component list?

Example,

label=Label(text='put me first')

row=DataRowPanel()
row.add_component(label, column=1)

comps=self.data_grid_1.get_components()
comps.insert(1, row)

self.data_grid_1.clear()

for c in comps:
  self.data_grid_1.add_component(c)

Iā€™m not sure if there is another way to do this without having to clear and then re-add components.

1 Like

maybe I was not clear, I am looking to make the process of adding row faster. When I do it normal way - add to data tables and refresh, it sometimes takes too long.

Maybe it would be faster to add and refresh just in browser ? Is it this recommended solution ? I could not make work your sample in my app yet.

Yes, I did not fully understand the question; however, you can see in the example above that a row is instantly added to the data grid. Perhaps you can extrapolate that approach to your app (if client-side processing is suitable for you).

The bottlenecks are usually round-trip server calls and the forum has lots of tips for optimizing in that area.

Here are some posts to read:

I have a highly experimental and non-Anvillic way of handling data grids. Itā€™s a 3rd party Javascript library called www.tabulator.info

I have a kind of working custom component which can add thousands of rows very quickly indeed. It has full pagination, etc. (well, look at the link for features).

I am working to make it better but if you want Iā€™ll send you a clone link to play with.

1 Like

I must be doing something wrong, because whena I am adding row, it takes too much time so I am going to check that out, thanks !

yes I would like to take a look at that, thank you !

Hi Jan and others

I know this post is a bit old, but I saw it while researching my own problem, came to my own solution and thought Iā€™d shareā€¦

So I also have a data grid with pretty cool data grid rows that are pretty dynamic and do a lot of things on their own depending on many variables, which results in an awesome presentation of data to the user. Only drawback is that when line is added, the standard

repeating_panel.items = updated_list

results in an irritating 2-3 seconds of waiting while each line starts its own data grid row from scratch.

My solution? Initiate the data grid row yourself, then add it to the data grid using add_components. Near instantaneous!

So lets say you have a data grid called data_grid_1, with a data row template called data_row.

Go to the data_row and add an argument such as:

class data_row(data_rowTemplate):
  def __init__(self, new=None,**properties):

ā€œnewā€ is where we will send the new item, instead of adding it to the repeating panelā€™s items.

So from the form where your data grid is:

from .data_row import data_row
new_line_info = {'one':1,'two':2}
my_new_line = data_row(new=new_line_info)
data_grid.add_component(my_new_line,index=1)

(index must be 1 because the columns (if youā€™re using them) are at 0)

Remember that youā€™ll have to amend the first few lines of data_row:

 if new: 
   self.item = new

Viola! Enjoy

Something I forgot to mention aboveā€¦be wary if you were using the repeating panel. The above method is adding data rows directly to the data grid and NOT to the repeating panel, so you cannot then use repeating_panel.items and so onā€¦

Iā€™m looking at this more than two years later, so Iā€™m wondering: is this still the best way to go about making a repeating panel add new lines on top and push down rows? Also, how would you add data to column 2? 3? Iā€™ve tried <row.add_component(label, column=2)> (for example), and it had no effect.