jQuery UI Widgets Forums Grid Toolbar and RowCount

This topic contains 1 reply, has 2 voices, and was last updated by  Dimitar 9 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Toolbar and RowCount #57565

    fritzfrancis
    Participant

    Hello Peter, Dimitar,

    I have been trying various ways to display the number of rows that the grid contains in a toolbar. I have tried the ready function, the binding complete with no avail. Here is a snippet of my code.

    grid.showtoolbar = true;
    grid.toolbarheight = 36;
    grid.rendertoolbar = function (toolbar)
    {
    toolbar.append
    (
    “<div style=’margin: 8px; font-size: 14px; font-weight: bold;’>” +
    “Displaying ” +
    “<span id=’spanRowCount’></span>” +
    ” records.</div>”
    );
    };
    grid.source = adapter;
    grid.ready = function ()
    {
    $(“#spanRowCount”).html($(“#jqxGrid” + settingsObject.GridID).jqxGrid(“getrows”).length);
    };

    $(“#jqxGrid” + settingsObject.GridID).jqxGrid(grid);

    $(“#jqxGrid” + settingsObject.GridID).on
    (
    “bindingcomplete”,
    function ()
    {
    $(“#spanRowCount”).html($(“#jqxGrid” + settingsObject.GridID).jqxGrid(“getrows”).length);
    }
    );

    $(“#jqxGrid” + settingsObject.GridID).on
    (
    “filter”,
    function ()
    {
    $(“#spanRowCount”).html($(“#jqxGrid” + settingsObject.GridID).jqxGrid(“getrows”).length);
    }
    );

    Toolbar and RowCount #57592

    Dimitar
    Participant

    Hello fritzfrancis,

    Here is an example that shows how to achieve this:

    <!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.selection.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.pager.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.columnsresize.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="../../scripts/demos.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                // prepare the data
                var source =
                {
                    datatype: "jsonp",
                    datafields: [
                        { name: 'countryName' },
                        { name: 'name' },
                        { name: 'population', type: 'float' },
                        { name: 'continentCode' },
                        { name: 'adminName1' }
                    ],
                    async: false,
                    url: "http://api.geonames.org/searchJSON",
                    data: {
                        featureClass: "P",
                        style: "full",
                        maxRows: 20,
                        username: "jqwidgets"
                    }
                };
    
                var dataAdapter = new $.jqx.dataAdapter(source,
                    {
                        formatData: function (data) {
                            data.name_startsWith = $("#searchField").val();
                            return data;
                        }
                    }
                );
    
                var span = $("<span id='spanRowCount'></span>");
    
                $("#jqxgrid").jqxGrid(
                {
                    width: 850,
                    source: dataAdapter,
                    columns: [
                        { text: 'City', datafield: 'name', width: 170 },
                        { text: 'Country Name', datafield: 'countryName', width: 200 },
                        { text: 'Population', datafield: 'population', cellsformat: 'f', width: 170 },
                        { text: 'Continent Code', datafield: 'continentCode', minwidth: 110 }
                    ],
                    showtoolbar: true,
                    autoheight: true,
                    ready: function () {
                        var numberOfRows = $("#jqxgrid").jqxGrid("getrows").length;
                        span.html(numberOfRows);
                    },
                    rendertoolbar: function (toolbar) {
                        toolbar.append(span);
                    }
                });
            });
        </script>
    </head>
    <body class='default'>
        <div id='jqxgrid'>
        </div>
    </body>
    </html>

    Best Regards,
    Dimitar

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

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

You must be logged in to reply to this topic.