Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
0
IgbDataGrid - IgbDateTimeColumn - How to custom format
posted

I would like to display my dates in my own custom format (like using a C# format string).

"yyyy-MMM-dd"

I have tried using

- DataBoundScript (script gets called, but cannot figure out how to change output)

- FormatOverrideScript (never seems to get called)

Any ideas?

  • 29105
    Offline posted

    Hello Terry, 

    There must a bug or limitation on setting FormatString to custom format. As of now there only 1 way to format with the columns directly which is a set of International DateTime formats. However if you want to customize the format to your liking I recommend using the IgbGrid. The IgbDataGrid is deprecated and I don't think we will put alot of effort in getting custom formats there. 

    In JS setup a file in wwwroot with the following:

    function OnFormatter(column, args) {
    //console.log(formatDate(args.OrderDate));
    return formatDate(args.OrderDate);
    
    }
    
    igRegisterScript("OnFormatter", OnFormatter, false);
    
    function formatDate(date) {
    
    const monthNames = ["Jan", "Feb", "Mar", "Apr",
    "May", "Jun", "Jul", "Aug",
    "Sep", "Oct", "Nov", "Dec"];
    
    var d = new Date(date),
    
    //month = '' + (d.getMonth() + 1),
    month = '' + monthNames[(d.getMonth())],
    day = '' + d.getDate(),
    year = d.getFullYear();
    
    //if (month.length < 2)
    // month = '0' + month;
    if (day.length < 2)
    day = '0' + day;
    
    return [year, month, day].join('-');
    }

    For more details please see the sample attached. 

    FormatDatesJS.zip