grid-dropdown-ds
by valchev
HTML
<script src="http://cdn.kendostatic.com/2012.1.322/js/kendo.all.min.js"></script>
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.metro.min.css">
<div id="example">
<table>
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Units</th>
<th>Delete</th>
</tr>
</thead>
<tbody data-template="row-template" data-bind="source: foo"></tbody>
</table>
</div>
<script id="row-template" type="text/x-kendo-template">
<tr>
<td style="width: 100%">
<input type="text" class="k-textbox" data-bind="value: name" maxlength="255" style="width: 100%" required/>
</td>
<td style="text-align: center; vertical-align: middle;">
<input type="checkbox" data-bind="checked: isDefault"/>
</td>
<td>
<input class="x-AddressType" data-bind="value: price"/>
</td>
<td>
<input type="button" class="k-button" data-bind="click: remove" value="X"/>
</td>
</tr>
</script>
JavaScript
var viewModel,
dsEmailAddresses = new kendo.data.DataSource({
transport: {
read: {
//using jsfiddle echo service to simulate JSON endpoint
url: "/echo/json/",
dataType: "json",
type: "POST",
data: {
// /echo/json/ echoes the JSON which you pass as an argument
json: JSON.stringify([
{ name: "Hampton Sofa", price: 989.99, isDefault: true },
{ name: "Perry Sofa", price: 559.99, isDefault: true },
{ name: "Donovan Sofa", price: 719.99, isDefault: true },
{ name: "Markus Sofa", price: 839.99, isDefault: true }
])
}
}
},
schema: {
model: {
fields: {
name: { type: "string" },
price: { type: "number" },
isDefault: { type: "boolean" }
}
}
}
});
dsEmailAddresses.fetch(function(){
viewModel = kendo.observable({
foo: Array.prototype.slice.apply(this.view()),
remove: function (e) {
if (confirm("Are you sure you wish to delete this email address?")) {
var addresses = this.get("foo");
addresses.splice(addresses.indexOf(e.data), 1);
}
}
});
kendo.bind($("#example"), viewModel);
});