Solved

Show Row Nbr in the grid

  • 17 July 2023
  • 4 replies
  • 68 views

Userlevel 4
Badge +1

Hi All,

 

I have created a new grid screen. Now I want to Show RowNbr in the Grid by adding a new column.

I tried to do that as below in my graph.

       [PXFilterable]
        public PXSelectJoinOrderBy<SOLine,
        InnerJoin<SOOrder, On<SOLine.orderType, Equal<SOOrder.orderType>,
            And<SOLine.orderNbr, Equal<SOOrder.orderNbr>>>,
        LeftJoin<InventoryItem, On<SOLine.inventoryID, Equal<InventoryItem.inventoryID>>>>,
        OrderBy<Asc<SOLine.orderNbr>>> Transactions;


        protected IEnumerable transactions()
        {
            var result = Transactions.Select();
            int rowNumber = 1;
            foreach (PXResult<SOLine> lineBoxed in result)
            {
                var line = lineBoxed.GetItem<SOLine>();
                var lineExt = line.GetExtension<SOLineExt>();
                lineExt.UsrRowNbr = rowNumber;
                rowNumber++;
            }

            return result;
        }
   

 But this freezes my screen as below.

 

Is there any Alternative way or fix for this?

Thanks

icon

Best answer by Zoltan Febert 17 July 2023, 23:56

View original

4 replies

Userlevel 7
Badge +17

Hi @charithalakshan49  I believe that adding line numbers to the GRID should not be done in the View Delegate. Instead, a more suitable approach would be to implement a Row_Inserting event to insert the row number using the same logic. I recommend checking and implementing this solution.

Userlevel 5
Badge +1

Hi @charithalakshan49 

Your approach seems to be correct, however, I'm assuming UsrRowNbr is a custom unbound field in an extension DAC SOLineExt. If that is the case, you need to ensure that UsrRowNbr is correctly set as an unbound field, and you have decorated it with PXUIField attribute and set its Visibility to PXUIVisibility.Visible to make sure it's visible in the grid. Also, the UsrRowNbr field should be added to the layout of the grid in the screen editor.

Here's how to define the unbound field:

 

public class SOLineExt : PXCacheExtension<SOLine>
{
#region UsrRowNbr
public abstract class usrRowNbr : PX.Data.BQL.BqlInt.Field<usrRowNbr> { }

[PXInt]
[PXUIField(DisplayName = "Row Nbr", Visibility = PXUIVisibility.Visible)]
public virtual int? UsrRowNbr { get; set; }
#endregion
}

Also, it's important to note that unbound fields only live in memory and their values are lost once the request ends. If you need the row number to persist, consider using a bound field instead. However, it's a bit more complicated because you'll need to manage its value across all records, not just those currently displayed.

Userlevel 6
Badge +3

Hi @charithalakshan49

You have a StackOverflowException in your first line of your function, because Transaction.Select() invokes your delegate again.

A possible fix is something like this:

        protected IEnumerable transactions()
{
var view = new PXView(this, true, Transactions.View.BqlSelect);

var totalRow = 0;
var startRow = PXView.StartRow;
var result = view.Select(PXView.Currents, PXView.Parameters, PXView.Searches,
PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRow);
PXView.StartRow = 0;

var rowNumber = 1;

foreach (PXResult<SOLine> lineBoxed in result)
{
var line = lineBoxed.GetItem<SOLine>();
var lineExt = line.GetExtension<SOLineExt>();
lineExt.UsrRowNbr = rowNumber;
rowNumber++;
}

return result;
}

Please refer for more details to this article: https://asiablog.acumatica.com/2016/06/using-pxview-in-dataview-delegate.html

Userlevel 4
Badge +1

@Naveen Boga @davidnavasardyan09  Thanks for your responses.

@zfebert56 you are correct there was a  StackOverflowException in the first line of my code. Your suggested code worked well. Thank you!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved