问题
I have a PXGraph with a data view delegate I want to override so I can add a a few more custom filters to the datas displayed on the grid.
I know how I can override and totaly replace the base delegate, but I dont know how I can execute the base logic of the dataview first, then add my filter to the result.
So the result I want to achieve is :
[PXOverride]
public virtual IEnumerable details()
{
var records = Base.details();
return records.Where(...);
}
I tried just copying the whole original dataview delegate but it calls a lot of privates members of the base graph so i'd have to copy all these members as well and it leads to a lot of ugly duplication in the code.
Edit : my problem is mainly that I can't call Base.details() because the details dataview delegate is declared as protected.
回答1:
Have a look at T200. It has an example. In your case, in your data view delegate, you should define a new BQL statement which matches the query of your main view. Perhaps you should not include any where statements, since you will add them a little further.
PXSelectBase<YourDAC> query = new <PXSelectReadyOnly<YourDAC,Where<...>.select(yourParams)
Further in your delegate, you can add additional where clauses using WhereAnd...So in your case, you add a filter to the query object like
query.WhereAnd<Where<SomeDAC>
Finally make sure your delegate returns the iterator. So you can call
return query.Select()
That query will execute with your custom filters you added. Hope this helps
回答2:
You were on the right track. The only thing left is to convert the IEnumerable collection to a List. You need to do this because Linq Where method doesn't operate on IEnumerable collection.
Here is an example calling Customer Payment Methods screen base details delegate and filtering the results using Linq:
using PX.Data;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace PX.Objects.AR
{
public class CustomerPaymentMethodMaint_Extension : PXGraphExtension<CustomerPaymentMethodMaint>
{
public virtual IEnumerable details()
{
List<CustomerPaymentMethodDetail> records = Base.details().RowCast<CustomerPaymentMethodDetail>().ToList();
return records.Where(record => record.Value == "Bob");
}
}
}
Results without the additional delegate filter:
Results with the additional delegate filter:
来源:https://stackoverflow.com/questions/52749492/how-to-invoke-the-base-method-of-a-dataview-delegate