Skip to main content
Solved

Filtering Acumatica Grid with Custom Column Values

  • 23 July 2024
  • 1 reply
  • 53 views

I added a new column to the grid in the "Prepare Replenishment" screen (IN50800) please refer the image below: 

Please note that I have marked the column header which is added as a custom column.

Please refer the code below:

namespace PX.Objects.IN.S
{
public class INItemSiteExt : PXCacheExtension<INItemSite>
{
public class ProgNameAttributeID : BqlString.Constant<ProgNameAttributeID>
{
public ProgNameAttributeID() : base("PROGNAME") { }
}

#region UsrProgramName

PXString(255, IsUnicode = true)]
PXUIField(DisplayName = "Program Name")]
public virtual string UsrProgramName { get; set; }
public abstract class usrProgramName : BqlString.Field<usrProgramName> { }

#endregion
}
}

Graph extension:

namespace PX.Objects.IN
{
public class INReplenishmentCreate_Extension : PXGraphExtension<INReplenishmentCreate>
{


#region Event Handlers

protected void INReplenishmentItem_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
INReplenishmentItem row = e.Row as INReplenishmentItem;
if (row == null) return;

var item = (InventoryItem)PXSelectorAttribute.Select<INReplenishmentItem.inventoryID>(cache, row);
if (item != null)
{
var attribute = (CSAnswers)PXSelect<CSAnswers,
Where<CSAnswers.refNoteID, Equal<Required<InventoryItem.noteID>>,
And<CSAnswers.attributeID, Equal<Required<CSAnswers.attributeID>>>>>
.Select(Base, item.NoteID, "PROGNAME");

if (attribute != null)
{
cache.SetValueExt<INItemSiteExt.usrProgramName>(row, attribute.Value.Trim());
}
}
}

#endregion

}
}

With above code it populates the values to the new added column but if I want to filter by it. Like below:

It doesn't filter most of the values, but sometimes it searches the first row of the grid. Otherwise it shows nothing.

Can anyone find any issues here or missing thing?

1 reply

Userlevel 6
Badge +3

Hi @oshadhat83,

It is never a good idea to populate field values in RowSelected event, it is always better do it in RowSelecting or FieldDefaulting events; or using PXDefault or PXUnboundDefault attributes.

Since your field is unbound, only RowSelecting and PXUnboundDefault would work.

Please see this code below, this is everything you need to solve this problem, you don’t need any graph extension.

public class INItemSiteExt : PXCacheExtension<INItemSite>
{
#region UsrProgramName

[PXString(255, IsUnicode = true)]
[PXUnboundDefault(typeof(SelectFrom<CSAnswers>
.InnerJoin<InventoryItem>.On<CSAnswers.refNoteID.IsEqual<InventoryItem.noteID>>
.Where<CSAnswers.attributeID.IsEqual<ProgNameAttributeID>
.And<InventoryItem.inventoryID.IsEqual<INItemSite.inventoryID.FromCurrent>>>
.SearchFor<CSAnswers.value>))]
[PXUIField(DisplayName = "Program Name")]
public virtual string UsrProgramName { get; set; }
public abstract class usrProgramName : BqlString.Field<usrProgramName> { }

#endregion
}

public class ProgNameAttributeID : BqlString.Constant<ProgNameAttributeID>
{
public ProgNameAttributeID() : base("PROGNAME") { }
}

 

Reply