jQWidgets Forums

jQuery UI Widgets Forums Grid Remove ALL groups

This topic contains 8 replies, has 2 voices, and was last updated by  Peter Stoev 12 years, 6 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • Remove ALL groups #11270

    grmbl
    Member

    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!

    Remove ALL groups #11274

    Peter Stoev
    Keymaster

    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 Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Remove ALL groups #11276

    grmbl
    Member

    Hi 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!

    Remove ALL groups #11277

    grmbl
    Member

    nvrmind, found it! groups.length instead of groups.length – 1

    Remove ALL groups #11280

    grmbl
    Member

    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…

    Remove ALL groups #11282

    grmbl
    Member

    …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?

    Remove ALL groups #11283

    Peter Stoev
    Keymaster

    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 Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Remove ALL groups #11284

    grmbl
    Member

    Thanks a lot, Peter! That did the trick.

    PS: Maybe you could implement ‘cleargroups’ in the jqxGrid API?

    Remove ALL groups #11291

    Peter Stoev
    Keymaster

    Thanks for the suggestion. We find that such method will be useful and we will implement it for the upcoming release.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.