我在自定义DAC /屏幕的字段上设置了PXSelector属性,该查询使用Acumatica属性(表CSAttributeDetail)进行查找,如下所示:
[PXSelector(typeof(Search<CSAttributeDetail.valueID,
Where<CSAttributeDetail.attributeID, Equal<Constants.toDoType>>,
OrderBy<Asc<CSAttributeDetail.sortOrder>>>),
typeof(CSAttributeDetail.valueID),
typeof(CSAttributeDetail.description))]
但是 - Order by似乎没有任何区别。有什么我需要添加以确保它由SortOrder订购?
这是属性列表的屏幕截图:
按照设计,PXSelectorAttribute只能按外键或替换键排序(如果有的话)。按任何其他字段排序将不起作用。
如果要以某种特殊方式排序,可以考虑创建自定义选择器,然后在方法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
}