<html>
<head>
<link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.rtl.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.default.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.dataviz.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.dataviz.default.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.mobile.all.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>
<script src="http://cdn.kendostatic.com/2013.2.716/js/cultures/kendo.culture.fr-CA.min.js"></script>
<script>
kendo.culture("fr-CA");
</script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div id="grid"></div>
<textarea style="width: 100%;" rows="10"></textarea>
</body>
</html>
var owners = [
{ id: 1, start:"10:01:00", oName: "John" , bId:1, mId:1, fullyPaid:1},
{ id: 2, start:"08:11:00",oName: "Mike" , bId:2, mId:4, fullyPaid:0 }
];
// array of all brands
var brands = [
{ id: 1, bName: "Ford" },
{ id: 2, bName: "BMW" }
];
// array of all models
var models = [
{ id: 1, mName: "Explorer", bId: 1},
{ id: 2, mName: "Focus", bId: 1},
{ id: 3, mName: "X3", bId: 2},
{ id: 4, mName: "X5", bId: 2}
];
$("#grid").kendoGrid({
dataSource: {
change: function(){
$("textarea").val(JSON.stringify(this.data(), true));
},
data: owners,
schema: {
model: {
id: "id",
fields: {
id: { editable: false }, // the id field is not editable
start:{},
oName:{},
bName:{},
mName:{},
fullyPaid:{type:"bool"}
}
}
}
},
editable: true,
columns: [
{ title:"Owners Name", field: "oName" },
{title:"Start", field: "start", format:"{0:HH:mm}", editor: timeEditor},
{
title: "Brand",
field: "bId",
template: "#= brandName(bId) #",
editor: brandEditor
},
{
title: "Model",
field: "mId",
template: "#= modelName(mId) #",
editor: modelEditor
},
{
title:"Fully Paid",
field:"fullyPaid"
}
]
});
function brandEditor(container, options) {
var input = $('<input id="bId" name="bId">');
input.appendTo(container);
input.kendoDropDownList({
dataTextField: "bName",
dataValueField: "id",
dataSource: brands,
change: function() {
options.model.set("mId", "");
}
});
}
function modelEditor(container, options) {
var input = $('<input id="mId" name="mId">');
var dataSource = new kendo.data.DataSource({
data: models,
filter: {
field: "bId",
operator: "eq",
value: options.model.bId
}
});
input.appendTo(container);
input.kendoDropDownList({
dataTextField: "mName",
dataValueField: "id",
dataSource: dataSource,
optionLabel: "Choose a model"
});
}
function timeEditor(container, options) {
$('<input data-text-field="' + options.field + '" data-value-field="' + options.field + '" data-bind="value:' + options.field + '" data-format="' + options.format + '"/>')
.appendTo(container)
.kendoTimePicker({
culture: "fr-CA",
interval: "15",
format: "HH:mm",
min: new Date(2013, 6, 24, 0, 0, 0, 0),
max: new Date(2013, 6, 24, 23, 59, 0, 0)
});
}
function brandName(id) {
for (var i = 0; i < brands.length; i++) {
if (brands[i].id == id) {
return brands[i].bName;
}
}
return "";
}
function modelName(id) {
for (var i = 0; i < models.length; i++) {
if (models[i].id == id) {
return models[i].mName;
}
}
return "";
}
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |