How to properly sort Tasks having multi-level Task Id like 1, 1.1, 1.1.5, 1.2, 2, 2.1.3, 2.2, 4, 11, 13, 44 etc. in Project Entry screen (PM301000)?

后端 未结 1 436
猫巷女王i
猫巷女王i 2021-01-24 10:57

Default Out-of-box Sorting:

Expected Sorting:

1条回答
  •  感情败类
    2021-01-24 11:22

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

    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 : BqlFormulaEvaluator, IBqlOperand
            where StringField : IBqlField
    {
        public override object Evaluate(PXCache cache, object item, 
                                        Dictionary pars)
        {
            PXFieldState fState = cache.GetStateExt(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.

    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
    {
        public abstract class usrSortingTaskCD : IBqlField { }
    
        [PXString(IsUnicode = true)]
        [PXUIField(DisplayName = "Usr Task")]
        [PXFormula(typeof(HierarchySorting))]
        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
    {
        public override void Initialize()
        {
            Base.Tasks.OrderByNew>>();
        }
    }
    

    0 讨论(0)
提交回复
热议问题