Kendo grid date column not formatting

前端 未结 7 797
悲哀的现实
悲哀的现实 2020-12-07 19:41

I have a KendoGrid like below and when I run the application, I\'m not getting the expected format for date column.

$(\"#empGrid\")         


        
相关标签:
7条回答
  • 2020-12-07 20:31

    The option I use is as follows:

    columns.Bound(p => p.OrderDate).Format("{0:d}").ClientTemplate("#=formatDate(OrderDate)#");
    
    function formatDate(OrderDate) {
        var formatedOrderDate = kendo.format("{0:d}", OrderDate);
    
        return formatedOrderDate;
    }
    
    0 讨论(0)
  • 2020-12-07 20:37

    This might be helpful:

    columns.Bound(date=> date.START_DATE).Title("Start Date").Format("{0:MM dd, yyyy}");
    
    0 讨论(0)
  • 2020-12-07 20:41

    I found this piece of information and got it to work correctly. The data given to me was in string format so I needed to parse the string using kendo.parseDate before formatting it with kendo.toString.

    columns: [
        {
            field: "FirstName",
            title: "FIRST NAME"
        },
        {
            field: "LastName",
            title: "LAST NAME"
        },
        {
            field: "DateOfBirth",
            title: "DATE OF BIRTH",
            template: "#= kendo.toString(kendo.parseDate(DateOfBirth, 'yyyy-MM-dd'), 'MM/dd/yyyy') #"
        },
    ...
    


    References:

    1. format-date-in-grid
    2. jsfiddle
    3. kendo ui date formatting
    0 讨论(0)
  • 2020-12-07 20:46

    just need putting the datatype of the column in the datasource

    dataSource: {
          data: empModel.Value,
          pageSize: 10,
          schema:  {
                    model: {
                        fields: {
                            DOJ: { type: "date" }
                                }
                           }
                   }  
               }
    

    and then your statement column:

     columns: [
        {
            field: "Name",
            width: 90,
            title: "Name"
        },
    
        {
            field: "DOJ",
            width: 90,
            title: "DOJ",
            type: "date",
            format:"{0:MM-dd-yyyy}" 
        }
    ]
    
    0 讨论(0)
  • 2020-12-07 20:46

    This is how you do it using ASP.NET:

    add .Format("{0:dd/MM/yyyy HH:mm:ss}"); 
    
        @(Html.Kendo().Grid<AlphaStatic.Domain.ViewModels.AttributeHistoryViewModel>()
                .Name("grid")
                .Columns(columns =>
                {
    
                    columns.Bound(c => c.AttributeName);
                    columns.Bound(c => c.UpdatedDate).Format("{0:dd/MM/yyyy HH:mm:ss}");   
                })
                .HtmlAttributes(new { @class = ".big-grid" })
                .Resizable(x => x.Columns(true))
                .Sortable()
                .Filterable()    
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .Batch(true)
                    .ServerOperation(false)
                            .Model(model =>
                            {
                                model.Id(c => c.Id);
                            })       
                   .Read(read => read.Action("Read_AttributeHistory", "Attribute",  new { attributeId = attributeId })))
                )
    
    0 讨论(0)
  • 2020-12-07 20:48

    Try formatting the date in the kendo grid as:

    columns.Bound(x => x.LastUpdateDate).ClientTemplate("#= kendo.toString(LastUpdateDate, \"MM/dd/yyyy hh:mm tt\") #");
    
    0 讨论(0)
提交回复
热议问题