Custom Elements Documentation
Getting Started
jqxSortable is a HTML Element which enables users to change the position of elements through drag and drop.Every UI element from jQWidgets toolkit needs its JavaScript files to be included in order to work properly.
The first step is to create html page and add links to the javascript files and
css dependencies to your project.
The jqxSortable element requires the following
files:
The next step is to add the html element within the body of the html page.<script type="text/javascript" src="../scripts/webcomponents-lite.min.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxcore.elements.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxdata.js"></script>
<script type="text/javascript" src="../jqwidgets/jqxsortable.js"></script>
The last step is to initialize the element settings:<jqx-sortable settings="elementSettings"></jqx-sortable>
To call a function(method), you need to pass the method name and parameters(if any) in the jqxSortable's instance.<script type="text/javascript">
JQXElements.settings["elementSettings"] =
{
appendTo:"document.body"
}
</script>
To get the result of a function after calling it, you can use the following syntax:<script>
window.onload = function () {
var element = document.querySelector("jqx-sortable");
element.cancelMethod();
}
</script>
To set a property(option), you need to use the property name and value(s) along with the jqxSortable's instance.<script>
window.onload = function () {
var element = document.querySelector("jqx-sortable");
var result = element.toArray();
}
</script>
You can also set properties of HTML Elements by using Attributes. Traditionally, attributes are used to set the initial state of an element. Properties with camelCase naming have dash-based attributes. For example: A property "dataSource" will have an attribute called "data-source".window.onload = function() {
document.querySelector("jqx-sortable").appendTo = ''parent'';
}
To get a property(option), you need to use the property name along with the jqxSortable's instance.
window.onload = function() {
var propertyValue = document.querySelector("jqx-sortable").appendTo;
}
Event binding can be defined in the HTML as an attribute. The syntax is: 'on-' and the event's name. Event Names with camelCase naming have dash-based attributes. The attribute's value is the event handler's name. The addEventListener
function can also be used for event binding.
<script>
window.onload = function () {
var element = document.querySelector("jqx-sortable");
element.addEventListener("activate", function(event){
// Your code here
});
}
</script>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title id='Description'>Sortable Custom Element</title>
<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" />
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
<link rel="stylesheet" href="../../styles/demos.css" type="text/css" />
<script type="text/javascript" src="../../scripts/webcomponents-lite.min.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script><script type="text/javascript" src="../../jqwidgets/jqxcore.elements.js"></script><script type="text/javascript" src="../../jqwidgets/jqxsortable.js"></script><script type="text/javascript" src="../../scripts/demos.js"></script><script>window.onload = function () {var firstNames = ["Nancy", "Andrew", "Janet", "Margaret", "Steven"];var lastNames = ["Davolio", "Fuller", "Leverling", "Peacock", "Buchanan"];var titles = ["Sales Representative", "Vice President, Sales", "Sales Representative", "Sales Representative", "Sales Manager"];var sortableList = '';for (var i = 0; i < firstNames.length; i++) {var imgurl = '../../images/' + firstNames[i].toLowerCase() + '.png';var img = '<img height="50" width="40" src="' + imgurl + '"/>';var element = '<div><table style="min-width: 130px;"><tr><td style="width: 40px;" rowspan="2">' + img + '</td><td>' + firstNames[i] + " " + lastNames[i] + '</td></tr><tr><td>' + titles[i] + '</td></tr></table></div>';sortableList = sortableList + element;}document.querySelector("jqx-sortable").innerHTML = sortableList;}JQXElements.settings["sortableSettings"] ={appendTo:"document.body"}</script><style type="text/css">jqx-sortable {margin: 2px;padding: 5px;float: left;width: 200px;border: lightblue solid 1px;}jqx-sortable div {border-radius: 5px;padding: 5px;cursor: pointer;background-color: white;color: black;border: 1px solid transparent;}jqx-sortable div:hover {border: 1px solid #356AA0;</style></head><body><jqx-sortable settings="sortableSettings"></jqx-sortable></body></html>