Posts Tagged ‘jQuery UI’

jQuery UI Multiselect is a widget that converts html multiple select inputs into slicker interfaces.

It makes searching within the options possible which is very functional for large lists & selected items can be re-ordered by drag’n drops.

jQuery UI Multi Select

It can display the number of selected items & for an easier selection, there are select all/deselect all links provided.

The widget is unobtrusive & and be styled with ThemeRoller.

IxEdit is an easy-to-use & free tool which aims to simplify the implementation of interactions on a web page, specially for anyone who is not experienced in JavaScript.

This interaction design tool is built with JavaScript & needs to be embedded into the webpage being edited. With the help of a modal-box-like interface, interactions created will be applied instantly.

Interaction Design Tool

Rather than totally new scripts, IxEdit generates jQuery & jQuery UI code using the parameters specified.

Interactions are stored in a local database (Google Gears), so, anything created won’t be lost even if the page is refreshed or closed.

After publishing ScheduledTweets yesterday, I received e-mails asking "how the drag’n drop & saving the new positions to the database was working".

Drag’n drop generally looks hard-to-apply but it is definitely not by using JavaScript frameworks. Here is, how it is done by using jQuery & jQuery UI:

jQuery Drag'n DropjQuery Drag'n Drop DemojQuery Drag'n Drop Download

The Database:

We create a simple database as below:

jQuery Drag'n Drop Database

The most important column in the database is recordListingID which shows us the order of the records.

This feature can be applied to any table by adding such a column to it.

The HTML:

We’ll be using an unordered list that is generated from a PHP query that lists the items according to the recordListingID value mentioned above.

Here it is:

</p>
<div id="contentLeft">
<ul>
    <li id="recordsArray_&lt;?php echo $row['recordID']; ?&gt;">&nbsp;</li>
</ul>
</div>
<p>

 

The JavaScript:

We will be using jQuery UI’s sortable plugin.

 <script type="text/javascript">
$(document).ready(function(){ 

	$(function() {
		$("#contentLeft ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
			var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
			$.post("updateDB.php", order, function(theResponse){
				$("#contentRight").html(theResponse);
			});
		}
		});
	});

});
</script> 

We made the unordered list inside #contentLeft a sortable item, used the serialize function of jQuery to create the array and posted it to updateDB.php.

The PHP:

After posting the array of "new order of the items" to updateDB.php, we must run a query to update our database that will reflect the last positions of every item:

<?php
require("db.php");

$action 				= $_POST['action'];
$updateRecordsArray 	= $_POST['recordsArray'];

if ($action == "updateRecordsListings"){

	$listingCounter = 1;
	foreach ($updateRecordsArray as $recordIDValue) {

		$query = "UPDATE records SET recordListingID = " . $listingCounter . " WHERE recordID = " . $recordIDValue;
		mysql_query($query) or die('Error, insert query failed');
		$listingCounter = $listingCounter + 1;
	}

	echo '<pre>';
	print_r($updateRecordsArray);
	echo '</pre>';
	echo 'If you refresh the page, you will see that records will stay just as you modified.';
}
?>

You can see that this is the easiest part. We handled the array as $updateRecordsArray and used it inside a for each statement.

With a new variable named $listingCounter, while the for each statement runs, we have updated the values of recordListingID column of every item in the database with $listingCounter values. And that’s it.

feed-holder
FeedBurner
  • 17% Off Web Hosting Sale - eTecc Web Hosting
  • activeCollab | Project Management
  • PSD to HTML
PSD to HTML
  • Manage your clients email marketing with sendcube
  • RapidxHTML - Converts Your PSD into XHTML Rapidly
  • MailChimp

Vivvo CMS - Web Publishing at your Fingertips

Popular Posts


Cheap SSL Certificates