jQWidgets Forums
jQuery UI Widgets › Forums › General Discussions › Dynamic contents
Tagged: ajax, content, contents, destroy, dynamic, dynamically, html, jqxgrid, jqxTabs, jqxtree, load, tab
This topic contains 4 replies, has 3 voices, and was last updated by Dimitar 10 years, 9 months ago.
-
AuthorDynamic contents Posts
-
I have a jqxTree and when a certain node is selected, I display a jqxGrid and popup edit. This works for me if all html is static, but if I attempt to load the html for the grid and popup from an external file using .load() when node is selected, I cannot make it work.
I want to create the illusion of working in a desktop environment so all functionality will be in one html file – thus it will become quite large so I try to split it up into file-components in order to isolate JS og HTML for each feature..
There can be all sorts of reason to why dynamic load doesnt work which is beyond me, so I starting digging and saw that the the jqxTab control can load contents dynamically. I have also noted that the suppliers demo page does something similar when selecting a running demo using a jqxNavigator, but it does not work as an ordinary jqxNavigator.
So my question is: Can I split up and load in the desired manner using jqxNavigator or jqxPanel or do I have to redesign on order to use a jqxTab instead?
All sorts of input regarding the overall issue of splitting up pages are most welcome.
Best regards
Soeren DalbyHello Soeren Dalby,
Here is how to dynamically load a jqxGrid by clicking an element of a jqxTree (the one with label Manufacturing):
<!DOCTYPE html><html lang="en"><head> <title id='Description'>jQuery Tree Sample</title> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <style type="text/css"> #grid_container { width: 800px; height: 800px; } </style> <script type="text/javascript" src="../scripts/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxpanel.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxtree.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script> <script type="text/javascript"> $(document).ready(function () { // Create jqxTree $('#jqxTree').jqxTree({ height: '300px', width: '300px' }); $('#jqxTree').bind('select', function (event) { var htmlElement = event.args.element; var item = $('#jqxTree').jqxTree('getItem', htmlElement); if (item && item.label == "Manufacturing") { $('#grid_container').load('Grid_Example.htm'); }; }); }); </script></head><body class='default'> <div id='jqxTree'> <ul> <li>Home</li> <li item-expanded='true'>Solutions <ul> <li>Education</li> <li>Financial services</li> <li>Government</li> <li>Manufacturing</li> <li>Solutions <ul> <li>Consumer photo and video</li> <li>Mobile</li> <li>Rich Internet applications</li> <li>Technical communication</li> <li>Training and eLearning</li> <li>Web conferencing</li> </ul> </li> <li>All industries and solutions</li> </ul> </li> </ul> </div> <div id="grid_container"> </div></body></html>
And here is the source code of Grid_Example.htm:
<!DOCTYPE html><html lang="en"><head> <script type="text/javascript"> $(document).ready(function () { // prepare the data var data = new Array(); var firstNames = [ "Andrew", "Nancy", "Shelley", "Regina", "Yoshi", "Antoni", "Mayumi", "Ian", "Peter", "Lars", "Petra", "Martin", "Sven", "Elio", "Beate", "Cheryl", "Michael", "Guylene" ]; var lastNames = [ "Fuller", "Davolio", "Burke", "Murphy", "Nagase", "Saavedra", "Ohno", "Devling", "Wilson", "Peterson", "Winkler", "Bein", "Petersen", "Rossi", "Vileid", "Saylor", "Bjorn", "Nodier" ]; var productNames = [ "Black Tea", "Green Tea", "Caffe Espresso", "Doubleshot Espresso", "Caffe Latte", "White Chocolate Mocha", "Cramel Latte", "Caffe Americano", "Cappuccino", "Espresso Truffle", "Espresso con Panna", "Peppermint Mocha Twist" ]; var priceValues = [ "2.25", "1.5", "3.0", "3.3", "4.5", "3.6", "3.8", "2.5", "5.0", "1.75", "3.25", "4.0" ]; for (var i = 0; i < 100; i++) { var row = {}; var productindex = Math.floor(Math.random() * productNames.length); var price = parseFloat(priceValues[productindex]); var quantity = 1 + Math.round(Math.random() * 10); row["firstname"] = firstNames[Math.floor(Math.random() * firstNames.length)]; row["lastname"] = lastNames[Math.floor(Math.random() * lastNames.length)]; row["productname"] = productNames[productindex]; row["price"] = price; row["quantity"] = quantity; row["total"] = price * quantity; data[i] = row; } var source = { localdata: data, datatype: "array" }; var dataAdapter = new $.jqx.dataAdapter(source, { loadComplete: function (data) { } }); $("#jqxgrid").jqxGrid( { width: 670, source: dataAdapter, columns: [ { text: 'First Name', datafield: 'firstname', width: 100 }, { text: 'Last Name', datafield: 'lastname', width: 100 }, { text: 'Product', datafield: 'productname', width: 180 }, { text: 'Quantity', datafield: 'quantity', width: 80, cellsalign: 'right' }, { text: 'Unit Price', datafield: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2' }, { text: 'Total', datafield: 'total', width: 100, cellsalign: 'right', cellsformat: 'c2' } ] }); }); </script></head><body class='default'> <div id='jqxWidget' style="font-size: 13px; font-family: Verdana; float: left;"> <div id="jqxgrid"> </div> </div></body></html>
Best Regards,
DimitarjqWidgets team
http://www.jqwidgets.com/Perfect, thanks
Hello Dimitar,
I’m new in jqWidgets and trying to make a dynamic tab content loader by using what you provided at the bottom.
I have one button to load dynamic html file in a tab content.
When I clicked for the first time to load the html file to tab content, everything ‘s OK but a problem arised when I destroyed a dynamically loaded tab and via the button I dynamically loaded the tab again and the result is nothing is displayed.
Can you help please ?Best regards,
kptrinhHello kptrinh,
Could you, please, post a sample code which demonstrates the issue so that we may be able to determine what causes it.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.