How to properly sort Tasks having multi-level Task

2020-04-21 03:41发布

Default Out-of-box Sorting:

enter image description here

Expected Sorting:

enter image description here

1条回答
We Are One
2楼-- · 2020-04-21 04:04

Set Edit Mask to Unicode for Project Task Segmented Key (CS202000) in order to allow multi-level Task CD (allowing . in value)

enter image description here

To get the expected sorting,

We will create custom BQL function which will pad the numeric portion to the out-of-box TaskCD field.

public class HierarchySorting<StringField> : BqlFormulaEvaluator<StringField>, IBqlOperand
        where StringField : IBqlField
{
    public override object Evaluate(PXCache cache, object item, 
                                    Dictionary<Type, object> pars)
    {
        PXFieldState fState = cache.GetStateExt<StringField>(item) as PXFieldState;
        return GetSortOrderValueExt(Convert.ToString(fState.Value));
    }

    public string GetSortOrderValueExt(string taskCD)
    {
        return Regex.Replace(taskCD, "[0-9]+", MatchReplacer => MatchReplacer.Value.PadLeft(10, '0'));
    }
}

This custom BQL function will pad zeros for any number in out-of-box TaskCD value.

enter image description here

We will create a new un-bound user defined field in DAC Extension of PMTask and will decorate with PXFormula having custom BQL function

public class PMTaskPXExt : PXCacheExtension<PMTask>
{
    public abstract class usrSortingTaskCD : IBqlField { }

    [PXString(IsUnicode = true)]
    [PXUIField(DisplayName = "Usr Task")]
    [PXFormula(typeof(HierarchySorting<PMTask.taskCD>))]
    public virtual string UsrSortingTaskCD { get; set; }
}

We will replace the sorting for the data view using the OrderByNew method of PXSelectBase/PXView.

public class ProjectEntryPXDemoExt : PXGraphExtension<ProjectEntry>
{
    public override void Initialize()
    {
        Base.Tasks.OrderByNew<OrderBy<Asc<PMTaskPXExt.usrSortingTaskCD>>>();
    }
}
查看更多
登录 后发表回答