jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Remove ALL groups
Tagged: jquery grid control, jquery grid grouping, jqxgrid
This topic contains 8 replies, has 2 voices, and was last updated by Peter Stoev 12 years, 6 months ago.
-
AuthorRemove ALL groups Posts
-
Anybody have an idea how to accomplish this?
I need the collection of groups so I can enumerate through it and perform removegroup(at)…thx!
Hi grmbl,
In our Grid control, you can get the collection of groups by doing the following:
var groups = $("#grid").jqxGrid('groups');
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
I’m doing this and the groups are not being cleared:
var groups = $("#ordergrid").jqxGrid('groups'); for (i = 0; i < groups.length - 1; i++) { $("#ordergrid").jqxGrid('removegroupat', i); }
Can you show me how to do it the right way?
thx!
nvrmind, found it! groups.length instead of groups.length – 1
hmmm, strange things happening when performing the removegroup.
by example I first add 3 groups and then run the following but there’s always 1 group remaining:var groups = $("#ordergrid").jqxGrid('groups'); $.each(groups, function (i, value) { $("#ordergrid").jqxGrid('removegroup', value); });
PS: yes I’ve changed from using the index to the string object in iteration because I had this problem even when using indices…
…seems like a bug, I’ve run it through dev console in Chrome and it seems that the groups object holds all
the string values for the groups but the ‘removegroup’ is not performing on the last group?Hi grmbl,
That happens because by calling the removegroup method, you change the groups array i.e your array is changed on every iteration of the loop. In order to achieve the desired results, you need to clone the groups array before looping through it.
Here’s a working sample:
<!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.8.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/jqxmenu.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.edit.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.filter.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.pager.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.grouping.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script> <script type="text/javascript" src="../../scripts/gettheme.js"></script> <script type="text/javascript"> $(document).ready(function () { var theme = getTheme(); var url = "../sampledata/customers.xml"; // prepare the data var source = { datatype: "xml", datafields: [ { name: 'CompanyName', map: 'm\\:properties>d\\:CompanyName' }, { name: 'ContactName', map: 'm\\:properties>d\\:ContactName' }, { name: 'ContactTitle', map: 'm\\:properties>d\\:ContactTitle' }, { name: 'City', map: 'm\\:properties>d\\:City' }, { name: 'PostalCode', map: 'm\\:properties>d\\:PostalCode' }, { name: 'Country', map: 'm\\:properties>d\\:Country' } ], root: "entry", record: "content", id: 'm\\:properties>d\\:CustomerID', url: url }; var dataAdapter = new $.jqx.dataAdapter(source); // Create jqxGrid $("#jqxgrid").jqxGrid( { width: 600, source: dataAdapter, groupable: true, groups: ['City', 'Country', 'CompanyName'], selectionmode: 'multiplecellsadvanced', theme: theme, columns: [ { text: 'Company Name', datafield: 'CompanyName', width: 250 }, { text: 'City', datafield: 'City', width: 120 }, { text: 'Country', datafield: 'Country' }, ] }); $("#Button").click(function () { var groups = $.extend({}, $("#jqxgrid").jqxGrid('groups')); $.each(groups, function () { $("#jqxgrid").jqxGrid('removegroup', this); }); }); }); </script></head><body class='default'> <div id="jqxgrid"> </div> <input type="button" value="Remove Groups" id="Button" /></body></html>
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThanks a lot, Peter! That did the trick.
PS: Maybe you could implement ‘cleargroups’ in the jqxGrid API?
Thanks for the suggestion. We find that such method will be useful and we will implement it for the upcoming release.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.