Hi Everyone,
In Acumatica 2018R1 we have a new cool feature to drag and drops rows of the grid to resort them.
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!
I want to do this with ListView Master. Does it work ? Because you mention about Master Detail view. I try call back function but no error and no change position with List View Master. Could you advice me.
Hi Vanna, I’m sorry but I haven’t tried it on the List View. But I suppose it can work too if you provide ordering key.
If that does not work, could you please create a support case?
When I attempt to set these values:
I get an error in the UI ‘Error: Unhandled exception has occurred, your changes have been rolled back: Sequence contains no elements’
These lines:
px:PXDSCallbackCommand Name=”PasteLine” Visible=”False” DependOnGrid=”grid” CommitChanges=”true”
px:PXDSCallbackCommand Name=”ResetOrder” Visible=”False” DependOnGrid=”grid” CommitChanges=”true”
I modified the ASPX instead of trying to configure the objects in the customization designer, and it allowed me to continue.
However, the grid still doesn’t allow me to drag ‘n drop. I’ve checked over your instructions multiple times.
Any help?
Daryl, could you please create a case on Acumatica Portal. Our team need to review your code.
I’m not at liberty to spend money on customization support.
Any chance a demo exists in Acumatica somewhere (or otherwise)?
Daryl,
You can check Acumatica Sales Orders or Generic Inquiry. Both of these screens have drag and drop examples.
nice post…
have a great day
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?
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.