Resort grid rows with Drag and Drop

Hi Everyone,

In Acumatica 2018R1 we have a new cool feature to drag and drops rows of the grid to resort them.

Resort grid rows with Drag and Drop

As you can see sorting is still based on database column (In my case it is Sort Order) but Acumatica can automatically reorder all rows based position you dropped it.
This is just a first version so still have some limitations (like it is still not fully works with extensions for existing DACs), but I really like we can  bring new and very friendly user experience to ERP.

How to implement it in own code? To have this feature you need to change several things in your Graph, DAC and Page:

Graph
In Graph we need to replace your normal PXSelect with new PXOrderedSelect. This data view has all logic to update sorting upon drop of the row.

public PXOrderedSelect<AAMaster, AADetail, 
      Where<AADetail.masterID, Equal<Current<AAMaster.masterID>>>, 
      OrderBy<Asc<AADetail.masterID, Asc<AADetail.sortOrder>>>> DetailsView;

Also PXOrderedSelect will add 2 new buttons (PastRow and ResetOrder) to graph actions that you may need to hide from Datasource actions later in the page.

DAC
In the DAC you need to implement interface ISortOrder, that requires to have LineNbr and SortOrder properties.

public class AADetail : IBqlTable, ISortOrder
  {
    #region LineNbr
    [PXDBInt(IsKey = true)]
    [PXUIField(DisplayName = "Line Nbr", Visible = false)]
    [PXLineNbr(typeof(AAMaster.masterCntr))]
    public virtual int? LineNbr { get; set; }
    public abstract class lineNbr : IBqlField { }
    #endregion
    #region SortOrder
    [PXDBInt()]
    [PXUIField(DisplayName = "Sort Order", Visible = false, Enabled = false)]
    public virtual int? SortOrder { get; set; }
    public abstract class sortOrder : IBqlField { }
    #endregion
  }

ASPX Page
In the page you need to do several things: hide actions, allow grid Drag&Drop and configure postback.

Here in data-source you need to hide commands:

<px:PXDataSource ... >
 <CallbackCommands>
  <px:PXDSCallbackCommand Name="PasteLine" Visible="False" DependOnGrid="grid" CommitChanges="true" />
  <px:PXDSCallbackCommand Name="ResetOrder" Visible="False" DependOnGrid="grid" CommitChanges="true" />
 </CallbackCommands>
</px:PXDataSource>

Here in grid you need to sync grid position, allow drag and drop and link PasteCommand with action.

<px:PXGrid SyncPosition="True" ID="grid" ... >
 <Mode InitNewRow="True" AllowDragRows="True" ></Mode>
 <CallbackCommands PasteCommand="PasteLine">
  <Save PostData="Container" />
 </CallbackCommands>
</px:PXGrid>

After this drag and drop should work as it shown on the grid before!

Hope it is helpful for you! Have a nice development!

3 Replies to “Resort grid rows with Drag and Drop”

    1. Several questions:

      – I’m assuming those two fields (SortOrder and LineNbr) need to be added to the SQL table as well – though you don’t mention that anywhere.
      – in the attribute [PXLineNbr(typeof(AAMaster.masterCntr))] – you don’t mention anywhere what AAMaster.masterCntr is or where it comes from or what it relates to.
      – How does this apply to grids that have a LineNbr attribute that is connected to the header DAC via the [LastLineNbr] attribute?

      1. Hi Peter,

        – I’m assuming those two fields (SortOrder and LineNbr) need to be added to the SQL table as well – though you don’t mention that anywhere.
        [SM] Yes, that also requires to add DB Columns to the appropriate tables. However LineNbr is usually is there already due to Parent/Child relationship.

        – in the attribute [PXLineNbr(typeof(AAMaster.masterCntr))] – you don’t mention anywhere what AAMaster.masterCntr is or where it comes from or what it relates to.
        [SM] PXLineNbr is usually used to define the child record key. Like in this example LineNbr field is marked as part of the key. masterCntr is working in combination with PXLineNbr to store somewhere the last number to numerate new LineNbr-s when record is inserted. PXLineNbr is greatelly explained in T220 or T230 training guides.

        – How does this apply to grids that have a LineNbr attribute that is connected to the header DAC via the [LastLineNbr] attribute?
        [SM] Did some search but haven’t found [LastLineNbr] in Acumatica repository. Is that attribute added with Customization?
        Anyway, you may have your own composite keys from your DAC. Most crucial part here is the SortOrder field. I haven’t tested but I guess it will work even without LineNbr key.

Leave a Reply

Your email address will not be published. Required fields are marked *