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

267 lines
8.0 KiB
HTML
Executable File

<!DOCTYPE html>
<html>
<head>
<title>API</title>
<meta charset="utf-8">
<link href="../content/shared/styles/examples-offline.css" rel="stylesheet">
<link href="../../styles/kendo.common.min.css" rel="stylesheet">
<link href="../../styles/kendo.rtl.min.css" rel="stylesheet">
<link href="../../styles/kendo.default.min.css" rel="stylesheet">
<link href="../../styles/kendo.default.mobile.min.css" rel="stylesheet">
<script src="../../js/jquery.min.js"></script>
<script src="../../js/jszip.min.js"></script>
<script src="../../js/kendo.all.min.js"></script>
<script src="../content/shared/js/console.js"></script>
<script>
</script>
</head>
<body>
<a class="offline-button" href="../index.html">Back</a>
<div id="example" role="application">
<div class="configurator">
<div class="header">Configurator</div>
<div class="box-col">
<h4>Working with selected items</h4>
<div class="box-col">
<ul class="options">
<li>
<h4>Transfer item</h4>
<button id="transfer-left">To left</button>
<button id="transfer-right">To right</button>
</li>
</ul>
</div>
<div class="box-col">
<ul class="options">
<li>
<h4>Move item</h4>
<button id="move-up">Move Up</button>
<button id="move-down">Move Down</button>
</li>
</ul>
</div>
<div class="box-col">
<ul class="options">
<li>
<h4>Enable/Disable item</h4>
<button id="disable">Disable</button>
<button id="enable">Enable</button>
</li>
</ul>
</div>
</div>
<div class="box-col">
<h4 class="clear">Add/Remove items</h4>
<div class="box-col">
<ul class="options">
<li>
<h4>Add item</h4>
<input type="text" id="add-textbox" name="name" value="New Product" />
<button id="add-item">Add</button>
</li>
</ul>
</div>
<div class="box-col">
<ul class="options">
<li>
<h4>Remove by text (Contains)</h4>
<input type="text" id="remove-textbox" name="name" value="Chef" />
<button id="remove-item">Remove</button>
</li>
</ul>
</div>
</div>
</div>
<div class="demo-section k-content wide">
<select id="listbox1"></select>
<select id="listbox2"></select>
<div id="appendto"></div>
</div>
<span id="staticNotification"></span>
</div>
<script>
$(document).ready(function () {
var notification = $("#staticNotification").kendoNotification({
autoHideAfter: 4000, appendTo: "#appendto",
animation: {
open: {
effects: "fade:in"
},
close: {
effects: "none"
}
}
}).data("kendoNotification");
var listbox1 = $("#listbox1").kendoListBox({
dataTextField: "ProductName",
dataValueField: "ProductID",
dataSource: {
type: "odata",
serverPaging: true,
transport: {
read: {
url: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Products",
}
},
pageSize: 10
},
connectWith: "listbox2",
}).data("kendoListBox");
var listbox2 = $("#listbox2").kendoListBox({
dataTextField: "ProductName",
dataValueField: "ProductID",
dataSource: []
}).data("kendoListBox");
function showMessage(message) {
notification.hide();
notification.error(message);
}
$("#transfer-left").click(function () {
if (listbox2.select().length > 0) {
listbox1.add(listbox2.dataItem(listbox2.select()));
listbox2.remove(listbox2.select());
}
else {
showMessage("Right ListBox should have selected item!");
}
})
$("#transfer-right").click(function () {
if (listbox1.select().length > 0) {
listbox2.add(listbox1.dataItem(listbox1.select()));
listbox1.remove(listbox1.select());
}
else {
showMessage("Left ListBox should have selected item!");
}
})
$("#enable").click(function () {
listbox1.enable(".k-item", true);
listbox2.enable(".k-item", true);
})
$("#disable").click(function () {
if (listbox1.select().length > 0 || listbox2.select().length > 0) {
listbox1.enable(listbox1.select(), false);
listbox2.enable(listbox2.select(), false);
}
else {
showMessage("You need to select an item to be disabled!");
}
})
$("#move-up").click(function () {
if (listbox1.select().length > 0) {
if (listbox1.select().first().index() > 0) {
var item = listbox1.select().first();
listbox1.reorder(item, item.index() - 1);
}
else {
showMessage("Selected item is already at first position!");
}
}
else {
showMessage("Left ListBox should have selected item!");
}
})
$("#move-down").click(function () {
if (listbox1.select().length > 0) {
if (listbox1.select().first().index() < listbox1.items().length - 1) {
var item = listbox1.select().first();
listbox1.reorder(item, item.index() + 1);
}
else {
showMessage("Selected item is already at last position!");
}
}
else {
showMessage("Left ListBox should have selected item!");
}
})
var Product = kendo.data.Model.define({
id: "ProductID",
fields: {
"ProductName": {
type: "string"
}
}
});
$("#add-item").click(function () {
var text = $("#add-textbox").val();
var item = listbox1.add(new Product({
ProductName: text
}));
})
$("#remove-item").click(function () {
var text = $("#remove-textbox").val().toLowerCase();
var items = listbox1.items();
for (var i = 0; i < items.length; i++) {
var dataItem = listbox1.dataItem(items[i]);
if (dataItem.ProductName.toLowerCase().indexOf(text) >= 0) {
listbox1.remove(items[i]);
}
}
})
});
</script>
<style>
.k-notification-wrap {
padding: 8px 30px!important;
}
#appendto {
margin-top: 5px;
height: 15px;
}
#appendto .k-i-error {
padding-right: 8px;
}
.box-col .options .k-textbox {
width: 115px;
}
.box h4 {
margin-top: 25px;
}
#example .demo-section {
overflow: hidden;
max-width: none;
width: 645px;
}
#example .k-listbox {
width: 275px;
height: 310px;
}
#example .k-listbox:first-of-type {
margin-right: 1px;
}
</style>
</body>
</html>