CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other

03 January, 2019

JqueryUI - Selectable

 Programing Coderfunda     January 03, 2019     Jquery, JqueryUI - Selectable     No comments   

JqueryUI - Selectable

jQueryUI provides selectable() method to select DOM element individually or in a group. With this method elements can be selected by dragging a box (sometimes called a lasso) with the mouse over the elements. Also, elements can be selected by clicking or dragging while holding the Ctrl/Meta key, allowing for multiple (non-contiguous) selections.

Syntax

The selectable() method can be used in two forms −
  • $(selector, context).selectable (options) Method
  • $(selector, context).selectable ("action", params) Method

$ (selector, context).selectable (options) Method

The selectable (options) method declares that an HTML element contains selectable items. The options parameter is an object that specifies the behavior of the elements involved when selecting.

Syntax

$(selector, context).selectable (options);
You can provide one or more options at a time using Javascript object. If there are more than one options to be provided, then you will separate them using a comma as follows −
$(selector, context).selectable({option1: value1, option2: value2..... });
The following table lists the different options that can be used with this method −
Sr.No.Option & Description
1appendTo This option is tells which element the selection helper (the lasso) should be appended to. By default its value is body.
2autoRefresh
This option if set to true, the position and size of each selectable item is computed at the beginning of a select operation. By default its value is true.
3cancel This option forbids selecting if you start selection of elements. By default its value is input,textarea,button,select,option.
4delay
This option is used to set time in milliseconds and defines when the selecting should start. This can be used to prevent unwanted selections. By default its value is 0.
5disabled
This option when set to true, disables the selection mechanism. Users cannot select the elements until the mechanism is restored using the selectable ("enable") instruction. By default its value is false.
6distance
This option is the distance (in pixels) the mouse must move to consider the selection in progress. This is useful, for example, to prevent simple clicks from being interpreted as a group selection. By default its value is 0.
7filter
This option is a selector indicating which elements can be part of the selection. By default its value is *.
8tolerance
This option specifies which mode to use for testing whether the selection helper (the lasso) should select an item. By default its value is touch.
The following section will show you a few working examples of selectable functionality.

Default Functionality

The following example demonstrates a simple example of selectable functionality, passing no parameters to the selectable() method.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI selectable-1</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<style>
#selectable-1 .ui-selecting { background: #707070 ; }
#selectable-1 .ui-selected { background: #EEEEEE; color: #000000; }
#selectable-1 { list-style-type: none; margin: 0;
padding
: 0; width: 20%; }
#selectable-1 li { margin: 3px; padding: 0.4em;
font
-size: 16px; height: 18px; }
.ui-widget-content {
background
: #cedc98;
border
: 1px solid #DDDDDD;
color
: #333333;
}
</style>
<script>
$
(function() {
$
( "#selectable-1" ).selectable();
});
</script>
</head>

<body>
<ol id = "selectable-1">
<li class = "ui-widget-content">Product 1</li>
<li class = "ui-widget-content">Product 2</li>
<li class = "ui-widget-content">Product 3</li>
<li class = "ui-widget-content">Product 4</li>
<li class = "ui-widget-content">Product 5</li>
<li class = "ui-widget-content">Product 6</li>
<li class = "ui-widget-content">Product 7</li>
</ol>
</body>
</html>
Let us save the above code in an HTML file selectableexample.htm and open it in a standard browser which supports javascript, you should see the following output. Now, you can play with the result −
Try to click on products, use CTRLS key to select multiple products.

Use of Delay and Distance

The following example demonstrates the usage of two options delay and distance in the selectable function of JqueryUI.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Selectable</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<style>
#selectable-2 .ui-selecting,#selectable-3 .ui-selecting {
background
: #707070 ; }
#selectable-2 .ui-selected,#selectable-3 .ui-selected {
background
: #EEEEEE; color: #000000; }
#selectable-2,#selectable-3 { list-style-type: none; margin: 0;
padding
: 0; width: 20%; }
#selectable-2 li,#selectable-3 li { margin: 3px; padding: 0.4em;
font
-size: 16px; height: 18px; }
.ui-widget-content {
background
: #cedc98;
border
: 1px solid #DDDDDD;
color
: #333333;
}
</style>

<script>
$
(function() {
$
( "#selectable-2" ).selectable({
delay
: 1000
});
$
( "#selectable-3" ).selectable({
distance
: 100
});
});
</script>
</head>

<body>
<h3>Starts after delay of 1000ms</h3>
<ol id = "selectable-2">
<li class = "ui-widget-content">Product 1</li>
<li class = "ui-widget-content">Product 2</li>
<li class = "ui-widget-content">Product 3</li>
</ol>
<h3>Starts after mouse moves distance of 100px</h3>
<ol id = "selectable-3">
<li class = "ui-widget-content">Product 4</li>
<li class = "ui-widget-content">Product 5</li>
<li class = "ui-widget-content">Product 6</li>
<li class = "ui-widget-content">Product 7</li>
</ol>
</body>
</html>
Let us save the above code in an HTML file selectableexample.htm and open it in a standard browser which supports javascript, you should see the following output. Now, you can play with the result −
Try to click on products, use CTRL key to select multiple products. You will notice that selection of the Product 1, Product 2 and Product 3 start after a delay of 1000ms. Selection of the Product 4, Product 5, Product 6 and Product 7 can't be done individually. The selection starts only after the mouse moves a distance of 100px.

Use of Filter

The following example demonstrates the usage of two options delay and distance in the selectable function of JqueryUI.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI selectable-4</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<style>
#selectable-4 .ui-selecting { background: #707070 ; }
#selectable-4 .ui-selected { background: #EEEEEE; color: #000000; }
#selectable-4 { list-style-type: none; margin: 0;
padding
: 0; width: 20%; }
#selectable-4 li { margin: 3px; padding: 0.4em;
font
-size: 16px; height: 18px; }
.ui-widget-content {
background
: #cedc98;
border
: 1px solid #DDDDDD;
color
: #333333;
}
</style>

<script>
$
(function() {
$
( "#selectable-4" ).selectable({
filter
: "li:first-child"
});
});
</script>
</head>

<body>
<ol id = "selectable-4">
<li class = "ui-widget-content">Product 1</li>
<li class = "ui-widget-content">Product 2</li>
<li class = "ui-widget-content">Product 3</li>
<li class = "ui-widget-content">Product 4</li>
<li class = "ui-widget-content">Product 5</li>
<li class = "ui-widget-content">Product 6</li>
<li class = "ui-widget-content">Product 7</li>
</ol>
</body>
</html>
Let us save the above code in an HTML file selectableexample.htm and open it in a standard browser which supports javascript, you should see the following output. Now, you can play with the result −
Try to click on products. You will notice that only first product can be selected.

$ (selector, context).selectable ("action", params) Method

The selectable ("action", params) method can perform an action on selectable elements, such as preventing selectable functionality. The action is specified as a string in the first argument (e.g., "disable" to stop the selection). Check out the actions that can be passed, in the following table.

Syntax

$(selector, context).selectable ("action", params);;
The following table lists the different actions that can be used with this method −
Sr.No.Action & Description
1destroy This action removes the selectable functionality of an element completely. The elements return to their pre-init state.
2disable This action deactivates the selectable functionality of an element. This method does not accept any arguments.
3enable This action enables the selectable functionality of an element. This method does not accept any arguments.
4option( optionName ) This action gets the value currently associated with the specified optionName.
5option() This action gets an object containing key/value pairs representing the current selectable options hash.
6option( optionName, value )
This action sets the value of the selectable option associated with the specified optionName. The argument optionName is name of the option to be set and value is the value to be set for the option.
7option( options ) This action is sets one or more options for the selectable. The argument options is a map of option-value pairs to be set.
8refresh This action causes the size and position of the selectable elements to be refreshed. Used mostly when the autoRefresh option is disabled (set to false). This method does not accept any arguments.
9widget This action returns a jQuery object containing the selectable element. This method does not accept any arguments.

Example

Now let us see an example using the actions from the above table. The following example demonstrates the use of disable() and option( optionName, value ) methods.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Selectable</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<style>
#selectable-5 .ui-selecting,#selectable-6 .ui-selecting {
background
: #707070 ; }
#selectable-5 .ui-selected,#selectable-6 .ui-selected {
background
: #EEEEEE; color: #000000; }
#selectable-5,#selectable-6 {
list
-style-type: none; margin: 0; padding: 0; width: 20%; }
#selectable-5 li,#selectable-6 li {
margin
: 3px; padding: 0.4em; font-size: 16px; height: 18px; }
.ui-widget-content {
background
: #cedc98;
border
: 1px solid #DDDDDD;
color
: #333333;
}
</style>

<script>
$
(function() {
$
( "#selectable-5" ).selectable();
$
( "#selectable-5" ).selectable('disable');
$
( "#selectable-6" ).selectable();
$
( "#selectable-6" ).selectable( "option", "distance", 1 );
});
</script>
</head>

<body>
<h3>Disabled using disable() method</h3>
<ol id = "selectable-5">
<li class = "ui-widget-content">Product 1</li>
<li class = "ui-widget-content">Product 2</li>
<li class = "ui-widget-content">Product 3</li>
</ol>
<h3>Select using method option( optionName, value )</h3>
<ol id = "selectable-6">
<li class = "ui-widget-content">Product 4</li>
<li class = "ui-widget-content">Product 5</li>
<li class = "ui-widget-content">Product 6</li>
<li class = "ui-widget-content">Product 7</li>
</ol>
</body>
</html>
Let us save the above code in an HTML file selectableexample.htm and open it in a standard browser which supports javascript, you should see the following output −
Try to click on products, use CTRL key to select multiple products. You will notice that Product 1, Product 2, and Product 3 are disabled. Selection of Product 4, Product 5, Product 6 and Product 7 happens after the mouse moves distance of 1px.

Event Management on Selectable Elements

In addition to the selectable (options) method which we saw in the previous sections, JqueryUI provides event methods which gets triggered for a particular event. These event methods are listed below −
Sr.No.Event Method & Description
1create(event, ui) This event is triggered when the selectable element is created. Where event is of type Event, and ui is of type Object.
2selected(event, ui) This event is triggered for each element that becomes selected. Where event is of type Event, and ui is of type Object.
3selecting(event, ui)
This event is triggered for each selectable element that’s about to get selected. Where event is of type Event, and ui is of type Object.
4start(event, ui) This event is triggered at the beginning of the select operation. Where event is of type Event, and ui is of type Object.
5stop(event, ui) This event is triggered at the end of the select operation. Where event is of type Event, and ui is of type Object.
6unselected(event, ui) This event is triggered at the end of the select operation for each element that becomes unselected. Where event is of type Event, and ui is of type Object.
7unselecting(event, ui) This event is triggered during select operation for each selected element that’s about to become unselected. Where event is of type Event, and ui is of type Object.

Example

The following example demonstrates the event method usage during selectable functionality. This example demonstrates the use of event selected.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI selectable-7</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<style>
#selectable-7 .ui-selecting { background: #707070 ; }
#selectable-7 .ui-selected { background: #EEEEEE; color: #000000; }
#selectable-7 { list-style-type: none; margin: 0;
padding
: 0; width: 20%; }
#selectable-7 li { margin: 3px; padding: 0.4em;
font
-size: 16px; height: 18px; }
.ui-widget-content {
background
: #cedc98;
border
: 1px solid #DDDDDD;
color
: #333333;
}
.resultarea {
background
: #cedc98;
border
-top: 1px solid #000000;
border
-bottom: 1px solid #000000;
color
: #333333;
font
-size:14px;
}
</style>

<script>
$
(function() {
$
( "#selectable-7" ).selectable({
selected
: function() {
var result = $( "#result" ).empty();
$
( ".ui-selected", this ).each(function() {
var index = $( "#selectable-7 li" ).index( this );
result
.append( " #" + ( index + 1 ) );
});
}
});
});
</script>
</head>

<body>
<h3>Events</h3>
<ol id = "selectable-7">
<li class = "ui-widget-content">Product 1</li>
<li class = "ui-widget-content">Product 2</li>
<li class = "ui-widget-content">Product 3</li>
<li class = "ui-widget-content">Product 4</li>
<li class = "ui-widget-content">Product 5</li>
<li class = "ui-widget-content">Product 6</li>
<li class = "ui-widget-content">Product 7</li>
</ol>
<span class = "resultarea">Selected Product</span>>
<span id = result class = "resultarea"></span>
</body>
</html>
Let us save the above code in an HTML file selectableexample.htm and open it in a standard browser which supports javascript, you should see the following output −
Try to click on products, use CTRL key to select multiple products. You will notice that the product number selected is printed at the bottom. 
By tutorialspoint

 

 

  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook

Related Posts:

  • JqueryUI - Selectable JqueryUI - Selectable jQueryUI provides selectable() method to select DOM element individually or in a group. With this method elements can be sel… Read More
  • JqueryUI - SelectableJqueryUI - SelectablejQueryUI provides selectable() method to select DOM element individually or in a group. With this method elements can be selecte… Read More
Newer Post Older Post Home

0 comments:

Post a Comment

Thanks

Meta

Popular Posts

  • Spring boot app (error: method getFirst()) failed to run at local machine, but can run on server
    The Spring boot app can run on the online server. Now, we want to replicate the same app at the local machine but the Spring boot jar file f...
  • Log activity in a Laravel app with Spatie/Laravel-Activitylog
      Requirements This package needs PHP 8.1+ and Laravel 9.0 or higher. The latest version of this package needs PHP 8.2+ and Laravel 8 or hig...
  • Laravel auth login with phone or email
          <?php     Laravel auth login with phone or email     <? php     namespace App \ Http \ Controllers \ Auth ;         use ...
  • Failed to install 'cordova-plugin-firebase': CordovaError: Uh oh
    I had follow these steps to install an configure firebase to my cordova project for cloud messaging. https://medium.com/@felipepucinelli/how...
  • Cashier package and Blade files
    I'm a little confused about this Cashier package. I installed it using the Laravel website (with composer), but noticed there's no...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (68)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

  • Failed to install 'cordova-plugin-firebase': CordovaError: Uh oh - 9/21/2024
  • pyspark XPath Query Returns Lists Omitting Missing Values Instead of Including None - 9/20/2024
  • SQL REPL from within Python/Sqlalchemy/Psychopg2 - 9/20/2024
  • MySql Explain with Tobias Petry - 9/20/2024
  • How to combine information from different devices into one common abstract virtual disk? [closed] - 9/20/2024

Laravel News

  • Auto-translate Application Strings with Laratext - 5/16/2025
  • Simplify Factory Associations with Laravel's UseFactory Attribute - 5/13/2025
  • Improved Installation and Frontend Hooks in Laravel Echo 2.1 - 5/15/2025
  • Filter Model Attributes with Laravel's New except() Method - 5/13/2025
  • Arr::from() Method in Laravel 12.14 - 5/14/2025

Copyright © 2025 CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda