{"id":490,"date":"2010-08-19T16:24:26","date_gmt":"2010-08-19T12:24:26","guid":{"rendered":"http:\/\/www.dhtmlx.com\/blog\/?p=490"},"modified":"2023-05-09T11:23:27","modified_gmt":"2023-05-09T08:23:27","slug":"easy-way-to-build-online-store-with-dhtmlxdataview","status":"publish","type":"post","link":"https:\/\/dhtmlx.com\/blog\/easy-way-to-build-online-store-with-dhtmlxdataview\/","title":{"rendered":"How to Build An Online Store with dhtmlxDataView"},"content":{"rendered":"<p>One of the highlighted additions in the latest release of DHTMLX was <a href=\"https:\/\/dhtmlx.com\/docs\/products\/dhtmlxDataView\/\" target=\"_blank\">dhtmlxDataView<\/a>, a new component that allows you to display a number of objects according to defined HTML templates and gives you the necessary features to manipulate these objects (e.g., filtering, searching, editing, etc.). <\/p>\n<p>In this tutorial, I will show you how easy it is to use dhtmlxDataView and to implement it in your own HTML pages. As an example, I will guide you on how to build an online store interface using dhtmlxDataView and some other DHTMLX widgets. Don&#8217;t worry \u2013 the story won&#8217;t be too long. It\u2019s mostly screenshots and code snippets :) <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/final_look.png\" alt=\"Book Store with dhtmlxDataView\" title=\"Online Book Store Interface Based on dhtmlxDataView\" width=\"280\" class=\"size-full wp-image-505\" align=\"left\" hspace=\"10\" vspace=\"12\" \/><\/p>\n<p>dhtmlxDataview is sort of a universal JavaScript component, and can be used to fulfill a whole range of user interface tasks, ranging from a simple image gallery to more sophisticated layouts for online stores. It all depends on your design needs, on the scope of your imagination, and probably, on your HTML knowledge :)<\/p>\n<p>The online book store we\u2019re going to build will not involve complex layouts, but only the required basics: a list of books, the ability to filter books by category, a shopping cart with selected items, and &#8211; most important &#8211; an order button. So let\u2019s get started.<\/p>\n<p><!--more--><\/p>\n<h4>Step 1 &#8211; Page Layout. What Should Be Displayed on Page?<\/h4>\n<p>First of all, we\u2019ll define the required functionality in our application and how the store will look. Let\u2019s summarize the features we need in our book store:<\/p>\n<ul style=\"font-size:13px;\">\n<li>Display the list of books with some necessary info: book name, author, price.<\/li>\n<li>The ability to filter books by categories.<\/li>\n<li>The ability to select books and put them into a separate container (shopping cart).<\/li>\n<li>Calculate the total price of the order.<\/li>\n<li>Make an order or empty the shopping cart.<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\nTo arrange the elements of the store interface, we will use the layout displayed in the sketch below. (In the header, we\u2019ll place a drop-down list with book categories for filtering):<\/p>\n<div id=\"attachment_493\" style=\"width: 496px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-493\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/scheme.png\" alt=\"The page layout\" title=\"The page layout\" width=\"486\" height=\"374\" class=\"size-full wp-image-493\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/scheme.png 486w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/scheme-300x230.png 300w\" sizes=\"auto, (max-width: 486px) 100vw, 486px\" \/><p id=\"caption-attachment-493\" class=\"wp-caption-text\">Online Store with dhtmlxDataView - Page Layout<\/p><\/div>\n<p>With this simple piece of HTML code, the page layout is ready:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\"><span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;data_container&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;navigation&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;category&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Category select box will be here<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;content&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;books_list&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;books_list_cont&quot;<\/span>&gt;<\/span>Books list will be here<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;books_selected&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;books_selected_cont&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;books_selected_data&quot;<\/span>&gt;<\/span>Selected books list will be here<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;total&quot;<\/span>&gt;<\/span>Total price displayed here<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><\/div><\/div>\n<p>In an online store, the number of books can reach hundreds or thousands of items, but with dhtmlxDataView, we can load even big lists quite fast.<\/p>\n<p>Note that dhtmlxDataView loads all the data to the client side, but renders only elements  that appear in the visible area (in our case, books in the list). This &#8220;smart rendering&#8221; feature continues to work when you scroll through the elements in DataView, displaying only those that need to be shown to a user.<\/p>\n<p>At the same time, the information for all the elements is already loaded into the browser, so the elements are available for filtering (or other operations, like sorting or searching). Building structures with DataView is quite easy, so we\u2019ll use it for both lists of books, in the store and in the cart. <\/p>\n<h4>Step 2 &#8211; DataView Initialization. How to Show Books List in DataView? <\/h4>\n<p>According to the page layout we created before, all available books will be shown in the &#8220;books_list_cont&#8221; container on the left.<\/p>\n<p>All the information about books is stored in the database and the table with books data has the following fields:<\/p>\n<ul style=\"font-size:13px;\">\n<li><strong>book<\/strong> &#8211; book title<\/li>\n<li><strong>author<\/strong> &#8211; book author<\/li>\n<li><strong>image<\/strong> &#8211; the image with book cover<\/li>\n<li><strong>category <\/strong>&#8211; book category: &#8220;Medicine&#8221;, &#8220;Computers &#038; Internet&#8221;, and others<\/li>\n<li><strong>price<\/strong> &#8211; book price<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\nBefore initializing dhtmlxDataView, we need to decide what fields to show in a DataView element, in this case, a book item. I think we should display all these fields, except category, and also add a button for book selection. Here is how our book item will look:<\/p>\n<div id=\"attachment_495\" style=\"width: 433px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-495\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/book_item.png\" alt=\"Online Store with dhtmlxDataView - Book Item\" title=\"Book Item\" width=\"423\" height=\"142\" class=\"size-full wp-image-495\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/book_item.png 423w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/book_item-300x100.png 300w\" sizes=\"auto, (max-width: 423px) 100vw, 423px\" \/><p id=\"caption-attachment-495\" class=\"wp-caption-text\">Online Store with dhtmlxDataView - Book Item<\/p><\/div>\n<p>dhtmlxDataView allows us to use HTML templates, so with the following code we&#8217;ll define a template for a book item (data fields are placed in # #):<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;books_list_template&quot;<\/span>&gt;<br \/>\n&nbsp; &nbsp; &lt;<span class=\"kw2\">img<\/span> <span class=\"kw3\">src<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'codebase\/books_icons\/#image#'<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'book_icon'<\/span> <span class=\"kw3\">style<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">''<\/span>&gt;<br \/>\n&nbsp; &nbsp; &lt;<span class=\"kw2\">div<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'book_info'<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"kw2\">div<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"kw2\">span<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'title'<\/span>&gt; Book: &lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"kw2\">span<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'book_name'<\/span>&gt; #book# &lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"kw2\">div<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"kw2\">span<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'title'<\/span>&gt; Author: &lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"kw2\">span<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'author_name'<\/span>&gt; #author# &lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"kw2\">div<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"kw2\">span<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'title'<\/span>&gt; Price: &lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"kw2\">span<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'price'<\/span>&gt; #price#$ &lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'select_button'<\/span> <span class=\"kw3\">onclick<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;select_clicked('#id#');&quot;<\/span>&gt;Select&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<br \/>\n&nbsp; &nbsp; &lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<br \/>\n&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/div><\/div>\n<p>dhtmlxDataView initialization is very easy. In the dhtmlxDataView constructor, we need to define the HTML container, template, height, and width of a book item. To load data, we need to pass the path to the DataView data into load() method. Like this:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">script<\/span>&gt;<br \/>\n&nbsp; &nbsp; books_list <span class=\"sy0\">=<\/span> new dhtmlXDataView<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; container: <span class=\"st0\">&quot;books_list_cont&quot;<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">type<\/span>:<span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; template: <span class=\"st0\">&quot;html-&gt;books_list_template&quot;<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">height<\/span>:<span class=\"nu0\">120<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">width<\/span>: <span class=\"nu0\">400<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; books_list.load<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;.\/data\/books_connector.php&quot;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/div><\/div>\n<p>The data is loaded from XML that is generated by the PHP script (&#8220;books_connector.php&#8221;). We&#8217;ll use <a href=\"https:\/\/dhtmlx.com\/docs\/products\/dhtmlxConnector\/\" target=\"_blank\">dhtmlxConnector<\/a> to retrieve data from the server. So what we need is to:<\/p>\n<ul style=\"font-size:13px;\">\n<li>Include connector libraries.<\/li>\n<li>Open  database connection.<\/li>\n<li>Create a connector object for DataView.<\/li>\n<li>Define the table and its fields which we want to load.<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\nHere is the PHP code:<\/p>\n<div class=\"codecolorer-container php default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\"><span class=\"kw2\">&lt;?php<\/span><br \/>\n<span class=\"kw1\">require_once<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;.\/connector\/dataview_connector.php&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw1\">require_once<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;.\/config.php&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"re0\">$conn<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw3\">mysql_connect<\/span><span class=\"br0\">&#40;<\/span><span class=\"re0\">$mysql_host<\/span><span class=\"sy0\">,<\/span><span class=\"re0\">$mysql_user<\/span><span class=\"sy0\">,<\/span><span class=\"re0\">$mysql_pass<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw3\">mysql_select_db<\/span><span class=\"br0\">&#40;<\/span><span class=\"re0\">$mysql_db<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"re0\">$data<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw2\">new<\/span> DataViewConnector<span class=\"br0\">&#40;<\/span><span class=\"re0\">$conn<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"re0\">$data<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">render_table<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;books&quot;<\/span><span class=\"sy0\">,<\/span><span class=\"st0\">&quot;id&quot;<\/span><span class=\"sy0\">,<\/span><span class=\"st0\">&quot;book,author,price,image,category&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"sy1\">?&gt;<\/span><\/div><\/div>\n<p>Now the book list is ready:<\/p>\n<div id=\"attachment_496\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-496\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-1.png\" alt=\"Online Store with dhtmlxDataView - Book List\" title=\"Book List\" width=\"600\" height=\"433\" class=\"size-full wp-image-496\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-1.png 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-1-300x216.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-496\" class=\"wp-caption-text\">Online Store with dhtmlxDataView - Book List<\/p><\/div>\n<h4>Step 3 &#8211; Adding Items and Properties. How to Select Books?<\/h4>\n<p>We\u2019ve already implemented the list with all the books in the store. The next step is to create a list with selected books, which will be also done using DataView.<\/p>\n<p>Selected books need to be shown in a separate list. Besides brief information about a book, the quantity ordered should also appear.<\/p>\n<div id=\"attachment_498\" style=\"width: 307px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-498\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/selected_book.png\" alt=\"Online Store with dhtmlxDataView - Selected Book \" title=\"Selected Book Item\" width=\"297\" height=\"71\" class=\"size-full wp-image-498\" \/><p id=\"caption-attachment-498\" class=\"wp-caption-text\">Online Store with dhtmlxDataView - Selected Book <\/p><\/div>\n<p>For this we&#8217;ll define another HTML template:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\"><span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;books_selected_template&quot;<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'selected_title'<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">span<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'selected_book'<\/span>&gt;<\/span>#book#<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">span<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'selected_author'<\/span>&gt;<\/span>#author#<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'selected_price'<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">span<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'title'<\/span>&gt;<\/span>Price:<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">span<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'price'<\/span>&gt;<\/span>#price#$<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'selected_quantity'<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">span<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'title'<\/span>&gt;<\/span>Quantity:<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"kw2\">span<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">'quantity_name'<\/span>&gt;<\/span>#quantity#<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><br \/>\n<span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/span><\/div><\/div>\n<p>This DataView initialization is similar to the previous one, but this time we don\u2019t load any data.<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">script<\/span>&gt;<br \/>\n&nbsp; &nbsp; books_selected <span class=\"sy0\">=<\/span> new dhtmlXDataView<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; container: <span class=\"st0\">&quot;books_selected_data&quot;<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">type<\/span>:<span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; template: <span class=\"st0\">&quot;html-&gt;books_selected_template&quot;<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">height<\/span>:<span class=\"nu0\">50<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">width<\/span>: <span class=\"nu0\">293<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">height<\/span>:<span class=\"st0\">&quot;auto&quot;<\/span>,<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; select: true<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/div><\/div>\n<p>A book will be added to this list when the &#8220;select&#8221; button in books_list of DataView is pressed. When a book is selected for the first time, we assign a &#8220;quantity&#8221; property for it, and increase its value each time the book is selected again. So one book can be ordered several times.<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">script<\/span>&gt;<br \/>\nfunction select_clicked<span class=\"br0\">&#40;<\/span><span class=\"kw3\">id<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"sy0\">\/\/<\/span>get <span class=\"kw3\">selected<\/span> <span class=\"kw3\">id<\/span><br \/>\n&nbsp; &nbsp; var &nbsp;<span class=\"kw3\">id<\/span> <span class=\"sy0\">=<\/span> books_list.locate<span class=\"br0\">&#40;<\/span>e<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"sy0\">\/\/<\/span>check is item already was added<br \/>\n&nbsp; &nbsp; var &nbsp;is_added <span class=\"sy0\">=<\/span> books_selected.exists<span class=\"br0\">&#40;<\/span><span class=\"kw3\">id<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; if &nbsp;<span class=\"br0\">&#40;<\/span>!is_added<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"sy0\">\/\/<\/span>copy item to the cart<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; books_list.copy<span class=\"br0\">&#40;<\/span><span class=\"kw3\">id<\/span>, <span class=\"nu0\">0<\/span>, books_selected, <span class=\"kw3\">id<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; books_selected.get<span class=\"br0\">&#40;<\/span><span class=\"kw3\">id<\/span><span class=\"br0\">&#41;<\/span>.quantity<span class=\"sy0\">=<\/span><span class=\"nu0\">1<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; books_selected.refresh<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; else <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; books_selected.get<span class=\"br0\">&#40;<\/span><span class=\"kw3\">id<\/span><span class=\"br0\">&#41;<\/span>.quantity++;<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; <span class=\"sy0\">\/\/<\/span>mark clicked item<br \/>\n&nbsp; &nbsp; books_list.select<span class=\"br0\">&#40;<\/span><span class=\"kw3\">id<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; books_selected.select<span class=\"br0\">&#40;<\/span><span class=\"kw3\">id<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; books_selected.refresh<span class=\"br0\">&#40;<\/span><span class=\"kw3\">id<\/span><span class=\"br0\">&#41;<\/span>; <br \/>\n<br \/>\n<span class=\"br0\">&#125;<\/span>;<br \/>\nbooks_list.on_click.select_button <span class=\"sy0\">=<\/span> select_clicked;<br \/>\n&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/div><\/div>\n<p>Here is what we have on the page &#8211; the list of books in the left pane and the list of selected books on the right:<\/p>\n<div id=\"attachment_499\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-499\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-2.png\" alt=\"Online Store with dhtmlxDataView - Selected Book List\" title=\"Selected Book List\" width=\"600\" height=\"433\" class=\"size-full wp-image-499\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-2.png 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-2-300x216.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-499\" class=\"wp-caption-text\">Online Store with dhtmlxDataView - Selected Book List<\/p><\/div>\n<p>Now we can select the books from the list and place them in a shopping cart container. But how do we remove them from the cart if they were added by mistake, or if we changed our mind about buying them?<\/p>\n<p>To change the number of ordered books, we set the onItemDblClick event handler. So a user will be able to remove unwanted copies of ordered books with a double-click, or delete a book from the order altogether:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">script<\/span>&gt;<br \/>\n&nbsp; &nbsp; books_selected.attachEvent<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;onItemDblClick&quot;<\/span>, dec_quantity<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; function dec_quantity<span class=\"br0\">&#40;<\/span><span class=\"kw3\">id<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; var book <span class=\"sy0\">=<\/span> books_selected.get<span class=\"br0\">&#40;<\/span><span class=\"kw3\">id<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; book.quantity--;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; if <span class=\"br0\">&#40;<\/span>book.quantity <span class=\"sy0\">==<\/span> <span class=\"nu0\">0<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; books_selected.remove<span class=\"br0\">&#40;<\/span><span class=\"kw3\">id<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span> else <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; books_selected.refresh<span class=\"br0\">&#40;<\/span><span class=\"kw3\">id<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/div><\/div>\n<p>So now we have an interface with the list of books and the shopping cart. We can select books from the list on the left, and they will be placed in the cart. Then we can choose the number of copies we would like to buy or remove the copies from the cart.<\/p>\n<h4>Step 4 &#8211; Data Filtering. How to Filter Books by Category? <\/h4>\n<p>Currently, all the books are loaded at once, and it\u2019s hard to find the item you need. Therefore, we\u2019ll add the option to filter books by category to make the search easier. We&#8217;ll use <a href=\"https:\/\/dhtmlx.com\/docs\/products\/dhtmlxCombo\/\" target=\"_blank\">dhtmlxCombo<\/a> to implement a category selection dropdown.<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">script<\/span>&gt;<br \/>\n&nbsp; &nbsp; var category<span class=\"sy0\">=<\/span>new dhtmlXCombo<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;category&quot;<\/span>, <span class=\"st0\">&quot;category&quot;<\/span>, <span class=\"nu0\">200<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; category.<span class=\"kw3\">readonly<\/span><span class=\"br0\">&#40;<\/span>true<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; category.loadXML<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;.\/data\/categories_connector.php&quot;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/div><\/div>\n<p>To filter the book list by selected category, we set the &#8220;onSelectionChange&#8221; event for the combo:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">script<\/span>&gt;<br \/>\n&nbsp; &nbsp; category.attachEvent<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;onSelectionChange&quot;<\/span>, select_category<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; function select_category<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; var cat <span class=\"sy0\">=<\/span> category.getSelectedValue<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; books_list.filter<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;#category#&quot;<\/span>, cat<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/div><\/div>\n<p>Now we can filter our books by category and, for example, display only books related to the subject of &#8220;Medicine&#8221;:<\/p>\n<div id=\"attachment_501\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-501\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-3.png\" alt=\"Online Store with dhtmlxDataView - Filtering\" title=\"Filtering\" width=\"600\" height=\"433\" class=\"size-full wp-image-501\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-3.png 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-3-300x216.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-501\" class=\"wp-caption-text\">Online Store with dhtmlxDataView - Filtering<\/p><\/div>\n<h4>Step 5 &#8211; Data Processing. How to Calculate the Order Price?<\/h4>\n<p>Below the list with selected books we need to place a container where the total price will appear:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;total&quot;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;Total: &lt;<span class=\"kw2\">span<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;total&quot;<\/span>&gt;<span class=\"nu0\">0<\/span>&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">span<\/span>&gt;$&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/div><\/div>\n<p>Each time the list is changed (user adds or removes a book from the cart), the total price should be recalculated:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">script<\/span>&gt;<br \/>\nfunction total_count<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; var price <span class=\"sy0\">=<\/span> <span class=\"nu0\">0<\/span>;<br \/>\n&nbsp; &nbsp; books_selected.<span class=\"kw3\">data<\/span>.each<span class=\"br0\">&#40;<\/span>function<span class=\"br0\">&#40;<\/span>book<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; price +<span class=\"sy0\">=<\/span>book.quantity*book.price;<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; document.getElementById<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;total&quot;<\/span><span class=\"br0\">&#41;<\/span>.innerHTML <span class=\"sy0\">=<\/span> price;<br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/div><\/div>\n<p>This function should be called when a book is selected\/added or deleted (select_clicked and dec_quantity functions in <b>Step 3<\/b>).<\/p>\n<div id=\"attachment_502\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-502\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-4.png\" alt=\"Online Store with dhtmlxDataView - Total Price\" title=\"Calculating Total Price\" width=\"600\" height=\"433\" class=\"size-full wp-image-502\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-4.png 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-4-300x216.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-502\" class=\"wp-caption-text\">Online Store with dhtmlxDataView - Total Price<\/p><\/div>\n<h4>Step 6 &#8211; Saving Data. How to Save the Order?<\/h4>\n<p>If you are still with me, we&#8217;re down to the last part of the tutorial &#8211; making an order. We&#8217;ll use a form to save an order:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">form<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;books_order&quot;<\/span> <span class=\"kw3\">action<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;order.php&quot;<\/span> <span class=\"kw3\">method<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;post&quot;<\/span>&gt;<br \/>\n&nbsp; &nbsp; &lt;<span class=\"kw2\">input<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;hidden&quot;<\/span> <span class=\"kw3\">id<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;order_list&quot;<\/span> <span class=\"kw3\">name<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;order_list&quot;<\/span> <span class=\"kw3\">value<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;&quot;<\/span> <span class=\"sy0\">\/<\/span>&gt;<br \/>\n&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">form<\/span>&gt;<\/div><\/div>\n<p>This form will be submitted when the <b>Order<\/b> button is clicked. We&#8217;ll place this button above selected books:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">div<\/span> <span class=\"kw3\">class<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;order_button&quot;<\/span> <span class=\"kw3\">onclick<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;order_selected();&quot;<\/span>&gt;Order&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">div<\/span>&gt;<\/div><\/div>\n<p>This is how our resulting interface looks:<\/p>\n<div id=\"attachment_503\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-503\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-5.png\" alt=\"Online Store with dhtmlxDataView - Final Result\" title=\"Final Result\" width=\"600\" height=\"433\" class=\"size-full wp-image-503\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-5.png 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/08\/step-5-300x216.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-503\" class=\"wp-caption-text\">Online Store with dhtmlxDataView - Final Result<\/p><\/div>\n<p>When the <b>Order<\/b> button clicked, this function will place the selected books and their  quantities in the hidden field and submit the form:<\/p>\n<div class=\"codecolorer-container html4strict default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">script<\/span>&gt;<br \/>\n&nbsp; &nbsp; function order_selected<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; var ids <span class=\"sy0\">=<\/span> <span class=\"st0\">''<\/span>;<br \/>\n&nbsp; &nbsp; books_selected.<span class=\"kw3\">data<\/span>.each<span class=\"br0\">&#40;<\/span> function<span class=\"br0\">&#40;<\/span>book<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; ids.push<span class=\"br0\">&#40;<\/span>book.<span class=\"kw3\">id<\/span> + <span class=\"st0\">&quot;=&quot;<\/span> + book.quantity<span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; document.getElementById<span class=\"br0\">&#40;<\/span><span class=\"st0\">'order_list'<\/span><span class=\"br0\">&#41;<\/span>.<span class=\"kw3\">value<\/span> <span class=\"sy0\">=<\/span> ids;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; document.getElementById<span class=\"br0\">&#40;<\/span><span class=\"st0\">'books_order'<\/span><span class=\"br0\">&#41;<\/span>.submit<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/div><\/div>\n<p>And that\u2019s all, at last :) I hope that this tutorial was clear and helpful, and now you have an idea how to create your own application interfaces with dhtmlxDataView. To those who read it to the end, thank you for your patience! :) To get a better understanding, you can view the demo, which demonstrates the interface we&#8217;ve built, or <a href=\"https:\/\/dhtmlx.com\/x\/download\/regular\/tutorials\/dataview_tutorial_sample.zip\">download the sources<\/a>.<\/p>\n<p><small>Posted by Alexandra Klenova<\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the highlighted additions in the latest release of DHTMLX was dhtmlxDataView, a new component that allows you to display a number of objects according to defined HTML &#8230;<\/p>\n","protected":false},"author":2,"featured_media":3370,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71,1],"tags":[33,14],"class_list":["post-490","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-uncategorized","tag-all-posts","tag-tips"],"_links":{"self":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/comments?post=490"}],"version-history":[{"count":1,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/490\/revisions"}],"predecessor-version":[{"id":10850,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/490\/revisions\/10850"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media\/3370"}],"wp:attachment":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media?parent=490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/categories?post=490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/tags?post=490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}