jQWidgets Forums

jQuery UI Widgets Forums Grid How to implement grouping in jqx grid using json object?

This topic contains 2 replies, has 2 voices, and was last updated by  abhishekkkk 10 years, 2 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author

  • abhishekkkk
    Participant

    Hi ,

    I want to implement grouping functionality in jqxgrid in my application.However, I have a json object containing multiple attributes instead of array object as given in demo in Jqx Widgets portals .Can anyone please provide me a sample example as how to acheive the same using json object.

    Thanks and Regards ,
    Abhishek


    Nadezhda
    Participant

    Hello Abhishek,

    Here is an example shows how to enable the grouping feature with ‘groupable’ property and how to set the Grid groups with ‘groups’ property. I hope it would be helpful.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title></title>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.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/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" src="../../jqwidgets/jqxgrid.columnsresize.js"></script> 
        <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script> 
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.grouping.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var url = "../sampledata/beverages.txt";
                // prepare the data
                var source =
                {
                    datatype: "json",
                    datafields: [
                        { name: 'name', type: 'string' },
                        { name: 'type', type: 'string' },
                        { name: 'calories', type: 'int' },
                        { name: 'totalfat', type: 'string' },
                        { name: 'protein', type: 'string' }
                    ],
                    id: 'id',
                    url: url
                };
                var dataAdapter = new $.jqx.dataAdapter(source);
                $("#jqxgrid").jqxGrid(
                {
                    width: 850,
                    source: dataAdapter,
                    columnsresize: true,
                    groupable: true,
                    groups: ['calories'],
                    columns: [
                      { text: 'Name', datafield: 'name', width: 250 },
                      { text: 'Beverage Type', datafield: 'type', width: 250 },
                      { text: 'Calories', datafield: 'calories', width: 180 },
                      { text: 'Total Fat', datafield: 'totalfat', width: 120 },
                      { text: 'Protein', datafield: 'protein', minwidth: 120 }
                    ]
                });
            });
        </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,
    Nadezhda

    jQWidgets team
    http://www.jqwidgets.com/


    abhishekkkk
    Participant

    Thanks Nadezhda.This is what I needed.

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

You must be logged in to reply to this topic.