首页 文章

如何在kendo网格列中的kendodatetimepicker中将今天的日期作为默认日期

提问于
浏览
0

我正在使用一个kendo网格,其中一列由 kendodatetimepicker 组成 . 用户只能在昨天和今天编辑日期和时间 .

So, when he clicks the edit button on the grid the datetimepicker should first show current date and time as default

我的网格看起来像这样 -

columns: [
          { field: "EntryType", title: "Entry Type", width: "50px", editor: $scope.typeDropDownEditor, template: "#=EntryType#" },
          { field: "Chemical", title: "Chemical Name", width: "50px", editor: $scope.chemicalDropDownEditor,template: "#=Chemical.ChemicalName#" },
          { field: "Facility", title: "Facility Name", width: "50px", editor: $scope.facilityDropDownEditor, template: "#=(Facility.FacilityName==null)? '' : Facility.FacilityName #" },
          { field: "RecordedDate", title: "Date - Time", format: 'yyyy-mm-dd HH:mm:ss', editor: dateTimeEditor, width: "50px" },
          { field: "Remarks",title:"Remarks",width:"60px"},
        { field: "Volume", title: "Volume", width: "50px" },
        {
            command: [
               {
                   name: "edit", title: "Edit", "template": "<a class='k-button k-grid-edit' href='' style='min-width:40px;' title=\"Edit\"><span class='k-icon k-i-edit'></span></a>"
               },
            ], field: "Actions",title:"Actions", width: "50px"
        }],
 editable: "inline",

datetimepicker 编辑 -

function dateTimeEditor(container, options) {
    $('<input data-text-field="' + options.field + '" data-value-field="' + options.field + '" data-bind="value:' + options.field + '" data-format="' + options.format + '"/>')
            .appendTo(container)
            .kendoDateTimePicker({
                value: $scope.tdate,
                dateInput: true,
                max: new Date(),
                min: $scope.ydate,
                //template: "#= kendo.toString(kendo.parseDate(value), 'yyyy-mm-dd HH:mm:ss') #"

            });
}

tdate和ydate定义为 -

var today = new Date();
    var yday = today.getDate() - 1;
    var tday = today.getDate();
    var month = today.getMonth();
    var year = today.getFullYear();
    var hour = today.getHours();
    var minute = today.getMinutes();
    var seconds = today.getSeconds();
    $scope.ydate = (new Date(year, month, yday, hour, minute, seconds));
    $scope.tdate = (new Date(year, month, tday, hour, minute, seconds));

Putting current date in value field is not giving the required output

1 回答

  • 0

    你可以尝试这个:StartDate是kendoDatePicker的id,你要在其中显示默认日期:

    HTML:

    <input id="datepickerjQuery">
    
        var todayDate = kendo.toString(kendo.parseDate(new Date()), 'MM/dd/yyyy');
      $("#datepickerjQuery").data("kendoDatePicker").value(todayDate);
    

相关问题