Latest web development tutorials
×

jQuery EasyUI Tutorial

jQuery EasyUI Tutorial jQuery EasyUI Introduction

jEasyUI application

jEasyUI Create a CRUD application jEasyUI Create a CRUD data grid jEasyUI Form CRUD application jEasyUI Create an RSS reader

jEasyUI Drag and drop

jEasyUI Basic drag and drop jEasyUI Create a drag-and-drop shopping cart jEasyUI Create a school curriculum

jEasyUI Menus and buttons

jEasyUI Create a simple menu jEasyUI Create a link button jEasyUI Create a menu button jEasyUI Create a split button

jEasyUI layout

jEasyUI Create a border layout jEasyUI Create a complex layout jEasyUI Creates a fold panel jEasyUI Create a tab page jEasyUI Dynamically add a tab jEasyUI Add the AutoPlay tab jEasyUI Create the XP style left panel

jEasyUI Data grid

jEasyUI Convert HTML tables to data grids jEasyUI Get the selected row data jEasyUI Add the query function jEasyUI Add a toolbar jEasyUI Create complex toolbars jEasyUI Sets the frozen column jEasyUI Dynamically change columns jEasyUI Format the column jEasyUI Set sort jEasyUI Custom sorting jEasyUI Create a column combination jEasyUI Add a check box jEasyUI Custom tab jEasyUI Enable in-line editing jEasyUI Extension editor jEasyUI Column operation jEasyUI Merge Cells jEasyUI Create a custom view jEasyUI Create a footer summary jEasyUI Condition Sets the line background color jEasyUI Create an attribute grid jEasyUI The extended line shows the details jEasyUI Create a subgrid jEasyUI Display massive data jEasyUI Add a paging component

jEasyUI window

jEasyUI Create a simple window jEasyUI Customize the Window Toolbar jEasyUI Window and layout jEasyUI Create a dialog box jEasyUI Customize the dialog box

jEasyUI Tree menu

jEasyUI Use the markup to create a tree menu jEasyUI Create an asynchronous tree menu jEasyUI Tree menu to add nodes jEasyUI Create a tree menu with check boxes jEasyUI Tree menu drag and drop control jEasyUI The Tree menu loads the parent / child nodes jEasyUI Create the base tree grid jEasyUI Create a complex tree grid jEasyUI Dynamic loading of tree jEasyUI The tree grid adds pagination jEasyUI Tree-lazy lazy-loading node

jEasyUI Form

jEasyUI Create an asynchronous submission form jEasyUI Form validation jEasyUI Create a tree drop-down box jEasyUI Format the drop-down box jEasyUI Filter down the data grid

jEasyUI Reference Manual

jQuery EasyUI Plugin jQuery EasyUI Extended

jQuery EasyUI drag - drag and drop to create a shopping cart

If you can through your Web applications simple to implement drag and drop, you know something special. By jQuery EasyUI, we can simply drag and drop functionality in Web applications.

In this tutorial, we'll show you how to create a user drag and drop items to enable users to buy the shopping cart page. Shopping basket of goods and prices will be updated.

Goods displayed on the page

	<Ul class = "products">
		<Li>
			<a href="#" class="item">
				<Img src = "images / shirt1.gif" />
				<Div>
					<P> Balloon </ p>
					<P> Price: $ 25 </ p>
				</ Div>
			</a>
		</ Li>
		<Li>
			<a href="#" class="item">
				<Img src = "images / shirt2.gif" />
				<Div>
					<P> Feeling </ p>
					<P> Price: $ 25 </ p>
				</ Div>
			</a>
		</ Li>
		<-! Other products ->
	</ Ul>

As you can see in the above code, we add a containing <ul> element number <li> element to display merchandise. All merchandise has a name and price properties, which is included in the <p> element.

Create a Shopping Cart

	<Div class = "cart">
		<H1> Shopping Cart </ h1>
		<Table id = "cartcontent" style = "width: 300px; height: auto;">
			<Thead>
				<Tr>
					<Th field = "name" width = 140> Name </ th>
					<Th field = "quantity" width = 60 align = "right"> Quantity </ th>
					<Th field = "price" width = 60 align = "right"> Price </ th>
				</ Tr>
			</ Thead>
		</ Table>
		<P class = "total"> Total: $ 0 </ p>
		<H2> Drop here to add to cart </ h2>
	</ Div>

We use the data grid (datagrid) to display the items in the shopping basket.

Drag the clone of goods

	$ ( '. Item'). Draggable ({
		revert: true,
		proxy: 'clone',
		onStartDrag: function () {
			. $ (This) .draggable ( 'options') cursor = 'not-allowed';
			. $ (This) .draggable ( 'proxy') css ( 'z-index', 10);
		},
		onStopDrag: function () {
			. $ (This) .draggable ( 'options') cursor = 'move';
		}
	});

Please note that we draggable attribute value from the 'proxy' is set to 'clone', so the drag element produced by cloning.

Place select items to the shopping cart

	$ ( '. Cart'). Droppable ({
		onDragEnter: function (e, source) {
			. $ (Source) .draggable ( 'options') cursor = 'auto';
		},
		onDragLeave: function (e, source) {
			. $ (Source) .draggable ( 'options') cursor = 'not-allowed';
		},
		onDrop: function (e, source) {
			. Var name = $ (source) .find ( 'p: eq (0)') html ();
			. Var price = $ (source) .find ( 'p: eq (1)') html ();
			addProduct (name, parseFloat (price.split ( '$') [1]));
		}
	});
	var data = { "total": 0, "rows": []};
	var totalCost = 0;
	function addProduct (name, price) {
		function add () {
			for (var i = 0; i <data.total; i ++) {
				var row = data.rows [i];
				if (row.name == name) {
					row.quantity + = 1;
					return;
				}
			}
			data.total + = 1;
			data.rows.push ({
				name: name,
				quantity: 1,
				price: price
			});
		}
		add ();
		totalCost + = price;
		. $ ( '# Cartcontent') datagrid ( 'loadData', data);
		$ ( 'Div.cart .total') html ( 'Total: $' + totalCost);.
	}	

Whenever the placement of goods, we get the first name and commodity prices, and then call 'addProduct' function to update the shopping basket.

Download jQuery EasyUI examples

jeasyui-dd-shopping.zip