Documentation
Getting Started
jqxSortable represents a jQuery plugin which allows you to reorder elements in a html list or div tags using the mouse.Every UI widget 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 widget requires the following files:
<head> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="../../jqwidgets/globalization/globalize.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxsortable.js"></script> <script async src="https://www.googletagmanager.com/gtag/js?id=G-2FX5PV9DNT"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'G-2FX5PV9DNT');</script></head>
The next step is to create html element within the body of the html document.
<div id="sortable"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> <div>6</div> <div>7</div> <div>8</div> <div>9</div></div>
The last step is to initialize the widget by adding the following script to the html document:
<script type="text/javascript"> $(document).ready(function () { $("#sortable").jqxSortable(); });</script>
To call a function(method), you need to pass the method name and parameters(if any) in the jqxSortable’s constructor.
To get the result of a function after calling it, you can use the following syntax:$("#jqxSortable").jqxSortable('refresh');
To set a property(option), you need to pass the property name and value(s) in the jqxSortable's constructor.var array = $("#jqxSortable").jqxSortable('toArray');
To get a property(option), you need to pass the property name to the jqxSortable's constructor.$("#jqxSortable").jqxSortable({ cancel: 'input' });
To bind to an event of a UI widget, you can use basic jQuery syntax. Let’s suppose that you want to get the selected date after the user clicks on a cell. The example code below demonstrates how to bind to the ‘valuechanged’ event of jqxSortable.var cancelElements = $("#jqxSortable").jqxSortable('cancel');
$('#jqxSortable').on('activate', function (event) {});
Basic Sample
<!DOCTYPE html><html lang="en"><head> <title id='Description'>jqxSortable plugin allows you to re-arrange html elements.</title> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="../../jqwidgets/globalization/globalize.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxsortable.js"></script> <style> #sortable { margin: 2px; padding: 5px; float: left; width: 200px; border: lightblue solid 1px; } #sortable div { border-radius: 5px; padding: 5px; background-color: white; color: black; border: 1px solid transparent; } #sortable div:hover { border: 1px solid #356AA0; } </style> <script type="text/javascript"> $(document).ready(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; } $("#sortable").html(sortableList); $("#sortable").jqxSortable(); }); </script><script async src="https://www.googletagmanager.com/gtag/js?id=G-2FX5PV9DNT"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'G-2FX5PV9DNT');</script></head><body> <div id="sortable"></div></body></html>