UNPKG

jqwidgets-framework

Version:

jQWidgets is an advanced Angular, Vue, Blazor, React, Web Components, jquery, ASP .NET MVC, Custom Elements and HTML5 UI framework.

108 lines (97 loc) 5.12 kB
<!DOCTYPE html> <html lang="en"> <head> <title id="Description">Integration of jqxListBox with Knockout</title> <link rel="stylesheet" href="../../../jqwidgets/styles/jqx.base.css" type="text/css" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" /> <script type="text/javascript" src="../../../scripts/jquery-1.12.4.min.js"></script> <script type="text/javascript" src="../../../scripts/json2.js"></script> <script type="text/javascript" src="../../../scripts/knockout-3.0.0.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxbuttons.js"></script> <script type="text/javascript" src="../../../scripts/demos.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxscrollbar.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxlistbox.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxdata.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxknockout.js"></script> <script type="text/javascript" src="../../../jqwidgets/jqxcheckbox.js"></script> <script type="text/javascript"> $(document).ready(function () { // View Model var listModel = function (items) { this.items = ko.observableArray(items); this.itemToAdd = ko.observable(""); this.disabled = ko.observable(false); this.selectedIndex = ko.observable(0); // add new item. this.addItem = function () { if (this.itemToAdd() != "") { this.items.push(this.itemToAdd()); // Adds the item. Writing to the "items" observableArray causes any associated UI to update. this.itemToAdd(""); // Clears the text box, because it's bound to the "itemToAdd" observable } } .bind(this); // Ensure that "this" is always this view model // remove item. this.removeItem = function () { this.items.pop(); } // sort items. this.sortItems = function () { var tmpString = Object.prototype.toString; Object.prototype.toString = (typeof field == "function") ? field : function () { return this[field] }; var comparer = function (value1, value2) { value1 = String(value1).toLowerCase(); value2 = String(value2).toLowerCase(); try { if (value1 < value2) { return -1; } if (value1 > value2) { return 1; } } catch (error) { var er = error; } return 0; }; this.items.sort(comparer); Object.prototype.toString = tmpString; } // get selected index. this.getIndex = function() { alert("Selected Index: " + this.selectedIndex()); } // set selected index. this.setIndex = function() { this.selectedIndex(1); } }; ko.applyBindings(new listModel(["Cortado", "Espresso", "Caffé Latte", "Breve"])); }); </script> </head> <body style='font-size: 13px; font-family: Verdana;' class='default'> <form data-bind="submit: addItem"> New item: <input data-bind='value: itemToAdd, valueUpdate: "afterkeydown"' /> <button data-bind="click: addItem, jqxButton: { }" type="submit"> Add</button> <button data-bind="click: removeItem, jqxButton:{ }"> Remove</button> <button data-bind="click: sortItems, jqxButton: { }"> Sort</button> <p> Your items:</p> <div id="list" data-bind="jqxListBox: {source: items, disabled: disabled, selectedIndex: selectedIndex, height: 200, width: 200}"> </div> <div data-bind="jqxCheckBox: {checked: disabled}" style='margin-top: 5px;' id="checkBox">Disabled</div> <div style="margin-top: 5px;"></div> <button data-bind="click: getIndex, jqxButton: { }"> Get Selected Index</button> <button data-bind="click: setIndex, jqxButton: { }"> Set Selected Index</button> </form> <div style="position: absolute; bottom: 5px; right: 5px;"> <a href="https://www.jqwidgets.com/" alt="https://www.jqwidgets.com/"><img alt="https://www.jqwidgets.com/" title="https://www.jqwidgets.com/" src="https://www.jqwidgets.com/wp-content/design/i/logo-jqwidgets.png"/></a> </div> </body> </html>