Acumatica dynamic dropdown

这一生的挚爱 提交于 2020-02-02 15:23:16

问题


I have a dropdown in a Grid and I want to fill it in runtime. I tried it in a RowSelected event but it doesn't work.

Then I tried it to assign the attribute PXStringList in the field definition on the DAC, but it doesn't work either.

This is the event

        protected virtual void HIASetupDetail_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
    {
        List<string> values = new List<string>();
        values.AddRange(new string[] { "A", "B" });

        if (e.Row == null)
        {
            return;
        }

        HIASetupDetail HIASetupDetailRow = (HIASetupDetail)e.Row;

        PXStringListAttribute.SetList<HIASetupDetail.acumaticaField>(sender, HIASetupDetailRow, values.ToArray(), values.ToArray());
    }

And this is the DAC

[System.SerializableAttribute()]
public class HIASetupDetail : PX.Data.IBqlTable
{        
    #region AcumaticaField
    public abstract class acumaticaField : PX.Data.IBqlField
    {
    }
    [PXDBString()]
    [PXDefault()]
    [PXUIField(DisplayName = "Acumatica Field")]
    public virtual string AcumaticaField { get; set; }
    #endregion


}

This is the Dropdown in the Grid

Any idea why it doesn't work in the Grid?


回答1:


Here is example how you can change the Values of the PXStringListAttribute while selecting that field:

The DAC Extension:

public class SOOrderExt:PXCacheExtension<SOOrder>
{

    #region TestField
    [PXString]
    [PXStringList()]
    [PXUIField(DisplayName = "Acumatica Field")]
    public string TestField { get; set; }

    public abstract class testField : IBqlField { }
    #endregion
}

The Graph Extension

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
    public virtual void SOOrder_TestField_FieldSelecting(PXCache sender,PXFieldSelectingEventArgs e)
    {
        if(e.Row!=null)
        {
            List<string> values = new List<string>();
            values.AddRange(new []{ "First","Second"});
            SOOrder row = (SOOrder)e.Row;
            PXStringListAttribute.SetList<SOOrderExt.testField>(sender, row, values.ToArray(), values.ToArray());
        }
    }
}

Also you should be sure that when you added the field to the Page from Layout Editor that it was added as "Combobox"

As a result you will get the following:

UPDATE 1 For changing the dropdown in the Grid you can use the following code as an example:

Graph Extension

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
    public virtual void SOLine_TestField_FieldSelecting(PXCache sender,PXFieldSelectingEventArgs e)
    {
        if(e.Row!=null)
        {
            List<string> values = new List<string>();
            values.AddRange(new[] { "First", "Second" });
            PXStringListAttribute.SetList<SOLineExt.testField>(sender, null, values.ToArray(), values.ToArray());
        }
    }
}

DAC Extension

public class SOLineExt : PXCacheExtension<SOLine>
{

    #region TestField
    [PXString]
    [PXStringList()]
    [PXUIField(DisplayName = "Acumatica Field")]
    public string TestField { get; set; }

    public abstract class testField : IBqlField { }
    #endregion
}

As you can see the difference is in the call of the PXStringListAttribute.SetList<T> in case of grid this is working only when passing null as row so that the change will be done for all lines.




回答2:


Here is an example I did a while ago that displays how to leverage CacheAttached method to dynamicaly populate a string list. It changes the available values depending on the current company.

public class DynamicDropdownAttribute : PXStringListAttribute
{
    private string[] Values2 = { "A", "C" };
    private string[] Labels2 = { "Alpha", "Charlie" };

    private string[] Values3 = { "N", "C" };
    private string[] Labels3 = { "November", "Charlie" };

    public DynamicDropdownAttribute()
        : base()
    {
    }

    public override void CacheAttached(PXCache sender)
    {
        base.CacheAttached(sender);
        var company = PX.Data.Update.PXInstanceHelper.CurrentCompany;
        if (company == 2)
        {
            this._AllowedValues = Values2;
            this._AllowedLabels = Labels2;
        }
        else if (company == 3)
        {
            this._AllowedValues = Values3;
            this._AllowedLabels = Labels3;
        }
    }
}

public class SOOrderPXExt : PXCacheExtension<SOOrder>
{
    [PXString(1)]
    [PXUIField(DisplayName = "Process")]
    [DynamicDropdown]
    public virtual string UsrProcess { get; set; }
    public abstract class usrProcess : IBqlField { }
}

The reason you need to use CacheAttached is explained in the T200 certification, available in Acumatica Open University. Here is an excerpt :




回答3:


The problem you count comes from the Grid control and not from DAC/Graph.

Because you set different cell formatting for each row, you need to set:

<px:PXGrid MatrixMode="True"


来源:https://stackoverflow.com/questions/49906357/acumatica-dynamic-dropdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!