jQuery UI Widgets Forums Grid jqxGrid, how to resize automatically width like table with %?

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

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

  • rmatinen
    Participant

    jqxGrid, how to use set its width like table can use %, then it can automatic resize upon container size change

    e.g. width: “100%”

    then its width can be automatic changed when container size change.


    Dimitar
    Participant

    Hello rmatinen,

    That is exactly what you would have to do – set the grid’s width to ‘100%’. You can see the grid’s fluid size support in action in the following demo: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/autosize.htm?arctic.

    Best Regards,
    Dimitar

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


    rmatinen
    Participant

    Thanks for reply,
    But i use grid in window in browser like desktop
    if i change size of window, i need to resize automatically gird to window
    for example if i determine width and height from percent to px and an event of when resize the window, i can resize the grid
    or i can to set resize grid automatically.
    thanks


    Dimitar
    Participant

    Hi rmatinen,

    Please check out the following example:

    <!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.11.1.min.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxwindow.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">
            $(document).ready(function () {
                $("#jqxwindow ").jqxWindow({
                    height: 300,
                    width: 350,
                    theme: 'summer',
                    resizable: true,
                    initContent: function () {
                        var data = new Array();
                        var firstNames = [
                                "Andrew", "Nancy", "Shelley", "Regina", "Yoshi", "Antoni", "Mayumi", "Ian", "Peter", "Lars", "Petra", "Martin", "Sven", "Elio", "Beate", "Cheryl", "Michael", "Guylene"
                            ];
                        var lastNames = [
                                "Fuller", "Davolio", "Burke", "Murphy", "Nagase", "Saavedra", "Ohno", "Devling", "Wilson", "Peterson", "Winkler", "Bein", "Petersen", "Rossi", "Vileid", "Saylor", "Bjorn", "Nodier"
                            ];
                        var productNames = [
                                "Black Tea", "Green Tea", "Caffe Espresso", "Doubleshot Espresso", "Caffe Latte", "White Chocolate Mocha", "Cramel Latte", "Caffe Americano", "Cappuccino", "Espresso Truffle", "Espresso con Panna", "Peppermint Mocha Twist"
                            ];
                        var priceValues = [
                                "2.25", "1.5", "3.0", "3.3", "4.5", "3.6", "3.8", "2.5", "5.0", "1.75", "3.25", "4.0"
                            ];
                        for (var i = 0; i < 100; i++) {
                            var row = {};
                            var productindex = Math.floor(Math.random() * productNames.length);
                            var price = parseFloat(priceValues[productindex]);
                            var quantity = 1 + Math.round(Math.random() * 10);
                            row["firstname"] = firstNames[Math.floor(Math.random() * firstNames.length)];
                            row["lastname"] = lastNames[Math.floor(Math.random() * lastNames.length)];
                            row["productname"] = productNames[productindex];
                            row["price"] = price;
                            row["quantity"] = quantity;
                            row["total"] = price * quantity;
                            data[i] = row;
                        }
                        var source = {
                            localdata: data,
                            datatype: "array"
                        };
                        var dataAdapter = new $.jqx.dataAdapter(source, {
                            loadComplete: function (data) { },
                            loadError: function (xhr, status, error) { }
                        });
                        $("#jqxgrid").jqxGrid({
                            width: '100%',
                            height: '100%',
                            source: dataAdapter,
                            columns: [{
                                text: 'First Name',
                                datafield: 'firstname',
                                width: '20%'
                            }, {
                                text: 'Last Name',
                                datafield: 'lastname',
                                width: '20%'
                            }, {
                                text: 'Product',
                                datafield: 'productname',
                                width: '20%'
                            }, {
                                text: 'Quantity',
                                datafield: 'quantity',
                                width: '20%',
                                cellsalign: 'right'
                            }, {
                                text: 'Unit Price',
                                datafield: 'price',
                                width: '10%',
                                cellsalign: 'right',
                                cellsformat: 'c2'
                            }, {
                                text: 'Total',
                                datafield: 'total',
                                width: '10%',
                                cellsalign: 'right',
                                cellsformat: 'c2'
                            }]
                        });
                    }
                });
            });
        </script>
    </head>
    <body>
        <div id='jqxwindow'>
            <div>
                Header</div>
            <div>
                <div id="jqxgrid">
                </div>
            </div>
        </div>
    </body>
    </html>

    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.