Files
2022-11-04 13:24:24 +02:00

85 lines
2.9 KiB
HTML
Executable File

<div data-role="view" data-init="initGrid" data-stretch="true" data-title="Adaptive Grid">
<div id="grid"></div>
</div>
<script>
function initGrid() {
var crudServiceBaseUrl = "https://demos.telerik.com/kendo-ui/service";
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
UnitPrice: { type: "number", validation: { required: true, min: 1} },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
mobile: "phone",
height: '500px',
resizable: true,
toolbar: ["create"],
columns: [
{ field:"ProductName", title: "Product Name", width: "200px" },
{ field: "UnitPrice", title:"Unit Price", format: "{0:c}", width: "120px" },
{ field: "UnitsInStock", title:"In Stock", width: "120px" },
{ field: "Discontinued", width: "120px" },
{ command: ["edit", "destroy"], title: "&nbsp;", width: "220px" }
],
editable: "popup",
filterable: true,
sortable: true,
columnMenu: true
});
}
</script>
<style>
/* Grid columns with no width are collapsed if the space is not enough, thus min-width on the tables is needed */
.k-grid table
{
min-width: 600px;
}
/* Android's default browser doesn't support properly min-width on tables */
media screen and (max-width: 699px) {
.km-phone .km-android .k-grid table
{
width: 600px;
}
}
</style>