Skip to main content
Question

Up down buttons on a grid


Hello, 
I’ve added 2 new buttons to a custom grid. An up arrow and a down arrow. I would like to be able to move row items up and down the grid. The sequence controls the order in which the sites/warehouses are checked in my code. 

A screen shot is above. The arrows button are highlighted. I have a field called ‘OrderNumber’ which stores the sequence of the items.
The RETAIL site is selected in the grid and I will press the Up Arrow button. ..

After pressing the up arrow button, my code has changed the values in the Order Number field, and the Save button is now available. But the grid has not been refreshed. If I click on the refresh button nothing happens. If I click on the Save button….

...the page and data is refreshed and the grid is reordered. 

 

The view which provides data to the grid looks like this

public SelectFrom<PinnSitePriority>            .Where<PinnSitePriority.siteid.IsEqual<INSite.siteID.FromCurrent>>.OrderBy<PinnSitePriority.orderNumber.Asc>
.View viewPinnSitePriority;
private void MoveRowByArrow(bool moveUp)
{
SequencingRows = true;
PinnSitePriority pinnSitePriority = viewPinnSitePriority.Current;
if (moveUp == true)
{
List<PinnSitePriority> l = viewPinnSitePriority.Cache.Cached.RowCast<PinnSitePriority>().ToList();
//code to reorder the items in the list - not shown to save space

//code to update the items in the cache
int? origNo = pinnSitePriority.OrderNumber;
pinnSitePriority.OrderNumber = p.OrderNumber;
p.OrderNumber = origNo;
//code to update the cache
viewPinnSitePriority.Cache.Update(pinnSitePriority);
viewPinnSitePriority.Cache.Update(p);
//attempts to refresh the grid
viewPinnSitePriority.Select();
viewPinnSitePriority.View.RequestRefresh();
}
else
{// moveDown code}
}

The code above is fired from the up/down action buttons. The idea is to change the numbers in the OrderNumber fields, update the cache and then update the grid with the results. I had hoped that calling RequestRefresh would refresh the view, including the OrderBy section but this doesn’t seem to be the case. 

Does anyone know how I can force the grid to update to reflect the updated ordering of the items in the cache. 

Thanks

Steve

7 replies

Userlevel 7
Badge +19

Hi @stephenward03  Up and Down concept is old functionality and Acumatica has introduced Drag functionality in the grid.

By using this functionality, we can drag the rows in the grid and sort the records.


Below is the article I recently implemented this for one of my projects, and this is a cool feature.

https://asiablog.acumatica.com/2018/04/resort-grid-rows-with-drag-and-drop.html

 

hope this helps!

Badge +12

Have you tried 

viewPinnSitePriority.View.Cache.Clear()

or

viewPinnSitePriority.View.Cache.ClearQueryCache()

after the update and before the reselect?

Userlevel 4
Badge +1

I would much prefer to use buttons than using drag drop - though drag drop would be a good back up to having the buttons. 

private void MoveRowByArrow(bool moveUp)
{
SequencingRows = true;
PinnSitePriority pinnSitePriority = viewPinnSitePriority.Current;
if (moveUp == true)
{
List<PinnSitePriority> l = viewPinnSitePriority.Cache.Cached.RowCast<PinnSitePriority>().ToList();
//code to reorder the items in the list - not shown to save space

//code to update the items in the cache
int? origNo = pinnSitePriority.OrderNumber;
pinnSitePriority.OrderNumber = p.OrderNumber;
p.OrderNumber = origNo;
//code to update the cache
viewPinnSitePriority.Cache.Update(pinnSitePriority);
viewPinnSitePriority.Cache.Update(p);
//attempts to refresh the grid
viewPinnSitePriority.View.Cache.Clear(); // clearing cached data
viewPinnSitePriority.View.Cache.ClearQueryCache(); // clearing cached queries.
viewPinnSitePriority.Select();
viewPinnSitePriority.View.RequestRefresh();
}
else
{// moveDown code}
}

I’ve added Clear and ClearQueryCache between update and the select. See above - is this what you meant?

But this just seems to clear the updates in the cache. The grid doesn’t change and Save button remains disabled. 

Thanks
Steve 

Badge +12

I didn’t necessarily mean both at the same time, but I was afraid maybe that is what would happen.

Userlevel 4
Badge +1

Actually, using just Cache.ClearQueryCache() seems to be working!
I’ll report back after more testing. 
Thanks
Steve

Userlevel 4
Badge +1

So it’s almost there. The up arrow and down arrow buttons change the sequence number, and the ClearQueryCache seems to reset the view so that items are displayed in the expected order. One final issue - the selected row in the grid doesn’t change - didn’t move up or down with the item which had been moved. So if you press the same arrow button again, the row items are simply switch back. 

On the image above I have selected TRUCK01 and I’m about to click on the up arrow button. 

TRUCK01 moves up, which is great, but the focus remains on the original row, so clicking the up arrow button again will just move WHOLESALE up a row. 

Is it possible to set the selected row in a grid?

Badge +12

Yes, you can. If I remember right, if you set SyncPosition = true, you can set a record to the View.Current property and it will be selected in the grid.

Reply