Kendo 日期选择器禁用 Kendo 网格列中的日期(kendo 网格中的日期范围)
Kendo datepicker disable dates in Kendo grid column (Date range in kendo grid)
我正在使用一个 kendogrid,它填充一些具有日期字段的数据。当它绑定到 kendogrid 时,我需要限制数据源中的日期。一个例子如下所示。在这里,我需要在 BirthDate 字段中禁用 25-Jan-1910(例如)之前的所有日期。
var data = createRandomData(50);
var autoCompleteDS = new kendo.data.DataSource({
data: [
{firstName: "Alex"},
{firstName: "Alice"},
{firstName: "Antony"},
{firstName: "Anne"},
{firstName: "Anna"}
]
});
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
data: data,
schema: {
model: {
fields: {
FirstName: { type: "string" },
LastName: { type: "string" },
City: { type: "string" },
Title: { type: "string" },
BirthDate: { type: "date" },
Age: { type: "number" }
}
}
},
pageSize: 10
},
height: 450,
scrollable: true,
sortable: true,
pageable: true,
editable: true,
edit: function(e) {
$(e.container)
.find("input[name='FirstName']")
.data("kendoAutoComplete")
.bind("change", function(e) {
console.log("auto complete changed");
});
},
toolbar: ["create"],
columns: [
{
field: "FirstName",
title: "First Name",
// width: 100
},
{
field: "BirthDate",
title: "Birth Date",
template: '#= kendo.toString(BirthDate,"MM/dd/yyyy") #'
},
{
field: "Age",
width: 100
},
]
});
});
<link href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.default.min.css" rel="stylesheet"/>
<link href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.common.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2012.2.710/js/kendo.all.min.js"></script><script src="http://demos.telerik.com/kendo-ui/content/shared/js/people.js"></script>
<!-- grid element -->
<div id="grid" style="width: 700px; margin: 0 auto;"></div>
您应该为 BirthDate
列定义一个编辑器函数来初始化 KendoDatePicker 并设置最小值。
editor: function(container, options) {
$('<input data-text-field="' + options.field + '" data-value-field="' + options.field + '" data-bind="value:' + options.field + '" data-format="' + options.format + '"/>')
.appendTo(container)
.kendoDatePicker({
min: new Date(1910, 0, 25)
});
}
您的代码片段将类似于:
var data = createRandomData(50);
var autoCompleteDS = new kendo.data.DataSource({
data: [
{firstName: "Alex"},
{firstName: "Alice"},
{firstName: "Antony"},
{firstName: "Anne"},
{firstName: "Anna"}
]
});
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
data: data,
schema: {
model: {
fields: {
FirstName: { type: "string" },
LastName: { type: "string" },
City: { type: "string" },
Title: { type: "string" },
BirthDate: { type: "date" },
Age: { type: "number" }
}
}
},
pageSize: 10
},
height: 450,
scrollable: true,
sortable: true,
pageable: true,
editable: true,
edit: function(e) {
$(e.container)
.find("input[name='FirstName']")
.data("kendoAutoComplete")
.bind("change", function(e) {
console.log("auto complete changed");
});
},
toolbar: ["create"],
columns: [
{
field: "FirstName",
title: "First Name",
width: 100
},
{
field: "BirthDate",
title: "Birth Date",
width: 100,
format: "{0:MM/dd/yyyy}",
parseFormats: [ "MM/dd/yyyy" ],
editor: function(container, options) {
$('<input data-text-field="' + options.field + '" data-value-field="' + options.field + '" data-bind="value:' + options.field + '" data-format="' + options.format + '"/>')
.appendTo(container)
.kendoDatePicker({
min: new Date(1910, 0, 25)
});
}
},
{
field: "Age",
width: 100
}
]
});
});
html {
font-size: 11px;
}
<link href="http://cdn.kendostatic.com/2014.3.1314/styles/kendo.default.min.css" rel="stylesheet"/>
<link href="http://cdn.kendostatic.com/2014.3.1314/styles/kendo.common.min.css" rel="stylesheet"/>
<script src="http://cdn.kendostatic.com/2014.3.1314/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2014.3.1314/js/kendo.all.min.js"></script><script src="http://demos.telerik.com/kendo-ui/content/shared/js/people.js"></script>
<!-- grid element -->
<div id="grid" style="width: 700px; margin: 0 auto;"></div>
我正在使用一个 kendogrid,它填充一些具有日期字段的数据。当它绑定到 kendogrid 时,我需要限制数据源中的日期。一个例子如下所示。在这里,我需要在 BirthDate 字段中禁用 25-Jan-1910(例如)之前的所有日期。
var data = createRandomData(50);
var autoCompleteDS = new kendo.data.DataSource({
data: [
{firstName: "Alex"},
{firstName: "Alice"},
{firstName: "Antony"},
{firstName: "Anne"},
{firstName: "Anna"}
]
});
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
data: data,
schema: {
model: {
fields: {
FirstName: { type: "string" },
LastName: { type: "string" },
City: { type: "string" },
Title: { type: "string" },
BirthDate: { type: "date" },
Age: { type: "number" }
}
}
},
pageSize: 10
},
height: 450,
scrollable: true,
sortable: true,
pageable: true,
editable: true,
edit: function(e) {
$(e.container)
.find("input[name='FirstName']")
.data("kendoAutoComplete")
.bind("change", function(e) {
console.log("auto complete changed");
});
},
toolbar: ["create"],
columns: [
{
field: "FirstName",
title: "First Name",
// width: 100
},
{
field: "BirthDate",
title: "Birth Date",
template: '#= kendo.toString(BirthDate,"MM/dd/yyyy") #'
},
{
field: "Age",
width: 100
},
]
});
});
<link href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.default.min.css" rel="stylesheet"/>
<link href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.common.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2012.2.710/js/kendo.all.min.js"></script><script src="http://demos.telerik.com/kendo-ui/content/shared/js/people.js"></script>
<!-- grid element -->
<div id="grid" style="width: 700px; margin: 0 auto;"></div>
您应该为 BirthDate
列定义一个编辑器函数来初始化 KendoDatePicker 并设置最小值。
editor: function(container, options) {
$('<input data-text-field="' + options.field + '" data-value-field="' + options.field + '" data-bind="value:' + options.field + '" data-format="' + options.format + '"/>')
.appendTo(container)
.kendoDatePicker({
min: new Date(1910, 0, 25)
});
}
您的代码片段将类似于:
var data = createRandomData(50);
var autoCompleteDS = new kendo.data.DataSource({
data: [
{firstName: "Alex"},
{firstName: "Alice"},
{firstName: "Antony"},
{firstName: "Anne"},
{firstName: "Anna"}
]
});
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
data: data,
schema: {
model: {
fields: {
FirstName: { type: "string" },
LastName: { type: "string" },
City: { type: "string" },
Title: { type: "string" },
BirthDate: { type: "date" },
Age: { type: "number" }
}
}
},
pageSize: 10
},
height: 450,
scrollable: true,
sortable: true,
pageable: true,
editable: true,
edit: function(e) {
$(e.container)
.find("input[name='FirstName']")
.data("kendoAutoComplete")
.bind("change", function(e) {
console.log("auto complete changed");
});
},
toolbar: ["create"],
columns: [
{
field: "FirstName",
title: "First Name",
width: 100
},
{
field: "BirthDate",
title: "Birth Date",
width: 100,
format: "{0:MM/dd/yyyy}",
parseFormats: [ "MM/dd/yyyy" ],
editor: function(container, options) {
$('<input data-text-field="' + options.field + '" data-value-field="' + options.field + '" data-bind="value:' + options.field + '" data-format="' + options.format + '"/>')
.appendTo(container)
.kendoDatePicker({
min: new Date(1910, 0, 25)
});
}
},
{
field: "Age",
width: 100
}
]
});
});
html {
font-size: 11px;
}
<link href="http://cdn.kendostatic.com/2014.3.1314/styles/kendo.default.min.css" rel="stylesheet"/>
<link href="http://cdn.kendostatic.com/2014.3.1314/styles/kendo.common.min.css" rel="stylesheet"/>
<script src="http://cdn.kendostatic.com/2014.3.1314/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2014.3.1314/js/kendo.all.min.js"></script><script src="http://demos.telerik.com/kendo-ui/content/shared/js/people.js"></script>
<!-- grid element -->
<div id="grid" style="width: 700px; margin: 0 auto;"></div>