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

How to get today's date as default in kendodatetimepicker in a kendo grid column

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

因此,当他单击网格上的编辑按钮时,datetimepicker 应该首先默认显示当前日期和时间

我的网格是这样的--

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));

将当前日期放入值字段未提供所需的输出

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

Html:

<input id="datepickerjQuery">

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