jQWidgets Forums
jQuery UI Widgets › Forums › Lists › ListBox › grouping of items failed
Tagged: jqxListBox, listbox filtering, listbox group
This topic contains 4 replies, has 3 voices, and was last updated by Peter Stoev 10 years, 5 months ago.
-
Authorgrouping of items failed Posts
-
Howdy and Servus from Bavaria,
I try to arrange my records in a grouped list. In my special case the items can have the same label but different values and groups.
The result should looks like this:group1
item1
item2
item3
group2
item1
item2but in reality the result is:
group2
item1
item2
item1
item2
group1
item3now the code:
<!doctype html> <html lang="de"> <head> <meta charset="UTF-8"> <title>Test</title> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="../../scripts/demos.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.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/jqxlistbox.js"></script> <script type="text/javascript"> <!-- $(document).ready(function () { data=[{"value":"1","label":"item1","group":"group1"},{"value":"2","label":"item2","group":"group1"},{"value":"3","label":"item3","group":"group1"},{"value":"4","label":"item1","group":"group2"},{"value":"5","label":"item2","group":"group2"}]; var source = { datatype: "local", datafields: [ { name: 'label' , type: 'string' }, { name: 'group' , type: 'string' }, { name: 'value' , type: 'string' }, ], id: 'value', localdata: data }; var dataAdapt = new $.jqx.dataAdapter(source); dataAdapt.dataBind(); var records = dataAdapt.getRecordsHierarchy('label'); $('#jqxWidget').jqxListBox({ source: records}); }) //--> </script> </head> <body> <div id='content'> <div id='jqxWidget'> </div> </div> </body> </html>
has anybody an idea where is my failure?
Hi quietcry,
The solution can be found below:
<!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="../../scripts/demos.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.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/jqxdata.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script> </head> <body> <div id='content'> <script type="text/javascript"> $(document).ready(function () { data = [{ "value": "1", "label": "item1", "group": "group1" }, { "value": "2", "label": "item2", "group": "group1" }, { "value": "3", "label": "item3", "group": "group1" }, { "value": "4", "label": "item1", "group": "group2" }, { "value": "5", "label": "item2", "group": "group2" }]; var source = { datatype: "local", datafields: [ { name: 'label', type: 'string' }, { name: 'group', type: 'string' }, { name: 'value', type: 'string' }, ], id: 'value', localdata: data }; var dataAdapt = new $.jqx.dataAdapter(source); dataAdapt.dataBind(); $('#jqxWidget').jqxListBox({ source: dataAdapt.records }); }); </script> <div id='jqxWidget'> </div> </div> </body> </html>
You had to use the dataAdapt.records.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comMany thanks Peter,
it works.
Hi,
I am using the same method combined with jqxListBox Filtering, However, the filtering works well but the groups names remain in list, any solution to remove the empty groups from the list while filtering? a live example can be your website “API Reference” tab.Regards,
Hi sadegh,
The groups will not be removed, they will be empty but displayed. The filtering filters the ListBox items only.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.