属性列表上的PXSelector不按sortorder排序

时间:2017-04-24 14:41:40

标签: acumatica

我在一个字段上设置了PXSelector属性,用于自定义DAC /屏幕,使用Acumatica属性(表CSAttributeDetail)进行查找,如下所示:

         [PXSelector(typeof(Search<CSAttributeDetail.valueID, 
                            Where<CSAttributeDetail.attributeID, Equal<Constants.toDoType>>, 
                            OrderBy<Asc<CSAttributeDetail.sortOrder>>>),
                     typeof(CSAttributeDetail.valueID),
                     typeof(CSAttributeDetail.description))]

但是 - 秩序似乎没有任何区别。我需要添加一些东西以确保它由SortOrder订购吗?

以下是属性列表的屏幕截图:

enter image description here

2 个答案:

答案 0 :(得分:0)

By design, the PXSelectorAttribute can only sort by foreign key or substitute key, if any defined. Sorting by any other field will make no effect.

答案 1 :(得分:0)

如果要以某种特殊方式进行排序,可以考虑创建自定义选择器,然后在方法GetRecords()中添加排序条件。

考虑以下代码示例:

public class SelectorCustomerContractAttribute : PXCustomSelectorAttribute
{
    private Type selectorField;
    private Type contractFld;

    public SelectorCustomerContractAttribute(Type selectorField, Type contractField)
        : base(typeof(DRDocumentRecord.refNbr))
    {
        if (selectorField == null)
            throw new ArgumentNullException("selectorField");

        if (contractField == null)
            throw new ArgumentNullException("contractField");


        if (BqlCommand.GetItemType(selectorField).Name != BqlCommand.GetItemType(selectorField).Name)
        {
            throw new ArgumentException(string.Format("moduleField and docTypeField must be of the same declaring type. {0} vs {1}",
                BqlCommand.GetItemType(selectorField).Name, BqlCommand.GetItemType(selectorField).Name));
        }

        this.selectorField = selectorField;
        contractFld = contractField;
    }

    public override void FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
    {           
    }

    protected virtual IEnumerable GetRecords()
    {
        var cache = this._Graph.Caches[BqlCommand.GetItemType(selectorField)];
        var cbs = (ContractBillingSchedule) cache.Current;
        cache = this._Graph.Caches[BqlCommand.GetItemType(contractFld)];
        var contract = (Contract) cache.Current;
        var result = new List<int>();

        if (cbs.BillTo == "M")
        {
            result.Add(1);
        }

        if (cbs.BillTo == "P")
        {
            result.Add(2);
        }
        if (cbs.BillTo == "S")
        {
            result.Add(3);
        }
        result.Add(4);
        return result.OrderBy(a => a.someCriteria);
    }
}

选择器的用法如下:

public class ContractBillingScheduleExt : PXCacheExtension<ContractBillingSchedule>
{
    #region UsrCustomerContact
    public abstract class usrCustomerContact : IBqlField, IBqlOperand
    {
    }
    [PXDBInt]
    [SelectorCustomerContract(typeof(ContractBillingSchedule.billTo), typeof(Contract.contractID))]
    [PXUIField(DisplayName = "Customer Contact", Visibility = PXUIVisibility.SelectorVisible)]
    public virtual int? UsrCustomerContact { get; set; }
    #endregion

}