jQuery UI Widgets Forums Grid Header row for grid

This topic contains 3 replies, has 3 voices, and was last updated by  Dimitar 7 years, 10 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • Header row for grid #49199

    tayling
    Participant

    Hi
    I enjoying using jqwidgets – any chance there is away to add a header row to a grid – above the column nsmae – so as to give it a title?

    Thanks
    Regards

    Tony Ayling

    Header row for grid #49201

    Dimitar
    Participant

    Hello Tony Ayling,

    It is possible to achieve this by using the grid’s toolbar. Here is an example, based on the demo Grouping:

    <!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="../../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.grouping.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.sort.js"></script>
        <script type="text/javascript" src="../../scripts/demos.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var url = "../sampledata/customers.xml";
    
                // prepare the data
                var source =
                {
                    datatype: "xml",
                    datafields: [
                        { name: 'CompanyName', map: 'm\\:properties>d\\:CompanyName', type: 'string' },
                        { name: 'ContactName', map: 'm\\:properties>d\\:ContactName', type: 'string' },
                        { name: 'ContactTitle', map: 'm\\:properties>d\\:ContactTitle', type: 'string' },
                        { name: 'City', map: 'm\\:properties>d\\:City', type: 'string' },
                        { name: 'PostalCode', map: 'm\\:properties>d\\:PostalCode', type: 'string' },
                        { name: 'Country', map: 'm\\:properties>d\\:Country', type: 'string' }
                    ],
                    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,
                    columns: [
                      { text: 'Company Name', datafield: 'CompanyName', width: 250 },
                      { text: 'City', datafield: 'City', width: 120 },
                      { text: 'Country', datafield: 'Country' }
                    ],
                    groups: ['City'],
                    showtoolbar: true,
                    toolbarheight: 20,
                    rendertoolbar: function (toolbar) {
                        var gridTitle = "<div style='width: 100%; height: 100%; text-align: center;'>Grid Title</div>";
                        toolbar.append(gridTitle);
                    }
                });
    
                $("#expand").jqxButton({ theme: theme });
                $("#collapse").jqxButton({ theme: theme });
                $("#expandall").jqxButton({ theme: theme });
                $("#collapseall").jqxButton({ theme: theme });
    
                // expand group.
                $("#expand").on('click', function () {
                    var groupnum = parseInt($("#groupnum").val());
                    if (!isNaN(groupnum)) {
                        $("#jqxgrid").jqxGrid('expandgroup', groupnum);
                    }
                });
    
                // collapse group.
                $("#collapse").on('click', function () {
                    var groupnum = parseInt($("#groupnum").val());
                    if (!isNaN(groupnum)) {
                        $("#jqxgrid").jqxGrid('collapsegroup', groupnum);
                    }
                });
    
                // expand all groups.
                $("#expandall").on('click', function () {
                    $("#jqxgrid").jqxGrid('expandallgroups');
                });
    
                // collapse all groups.
                $("#collapseall").on('click', function () {
                    $("#jqxgrid").jqxGrid('collapseallgroups');
                });
    
                // trigger expand and collapse events.
                $("#jqxgrid").on('groupexpand', function (event) {
                    var args = event.args;
                    $("#expandedgroup").text("Group: " + args.group + ", Level: " + args.level);
                });
    
                $("#jqxgrid").on('groupcollapse', function (event) {
                    var args = event.args;
                    $("#collapsedgroup").text("Group: " + args.group + ", Level: " + args.level);
                });
            });
        </script>
    </head>
    <body class='default'>
        <div id='jqxWidget' style="font-size: 13px; font-family: Verdana; float: left;">
            <div id="jqxgrid">
            </div>
            <div style="margin-top: 30px;">
                <div style="float: left; margin-left: 20px;">
                    <input value="Expand Group" type="button" id='expand' />
                    <br />
                    <input style="margin-top: 10px;" value="Collapse Group" type="button" id='collapse' />
                    <br />
                    <span style="margin-top: 10px;">Group:</span>
                    <input value="1" id="groupnum" style="margin-top: 10px; width: 20px;" type="text" />
                </div>
                <div style="float: left; margin-left: 20px;">
                    <input value="Expand All Groups" type="button" id='expandall' />
                    <br />
                    <input style="margin-top: 10px; margin-bottom: 10px;" value="Collapse All Groups"
                        type="button" id='collapseall' />
                    <br />
                </div>
                <div style="float: left; margin-left: 20px;">
                    <div style="font-weight: bold;">
                        <span>Event Log:</span>
                    </div>
                    <div style="margin-top: 10px;">
                        <span>Expanded Group:</span> <span id="expandedgroup"></span>
                    </div>
                    <div style="margin-top: 10px;">
                        <span>Collapsed Group:</span> <span id="collapsedgroup"></span>
                    </div>
                </div>
            </div>
        </div>
    </body>
    </html>

    Best Regards,
    Dimitar

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

    Header row for grid #88481

    padma
    Participant

    Hello,

    Is it possible to use a JqxTab with the title instead of a ‘Header Row’, to contain the nested grid?

    Thanks,
    Padma

    Header row for grid #88486

    Dimitar
    Participant

    Hello Padma,

    You can initialize a jqxGrid inside a jqxTabs, as shown in the following demo: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxtabs/integration.htm?light.

    Best Regards,
    Dimitar

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

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

You must be logged in to reply to this topic.