jQWidgets Forums

jQuery UI Widgets Forums Grid Card View Alternative

This topic contains 1 reply, has 2 voices, and was last updated by  Hristo 4 years, 1 month ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Card View Alternative #115144

    wsundet
    Participant

    My mobile app makes extensive use of Grid with many dropdown lists for field choices, and it works well. I have one category in my app that has many wide fields that do not display appropriately even in landscape mode.
    What I need is card view or a suitable alternative that can display the detail of an individual item while having the entire list of items available on the same screen.
    I have tried to use Card View with my Grid, but it appears that the Dropdown lists don’t lend themselves to Card View.

    Suggestions?

    Thank you.

    Card View Alternative #115164

    Hristo
    Participant

    Hello wsundet,

    I would like to ask you to provide us with one simple example that demonstrates your case.
    After that, I will try to provide you a solution to this.
    Meanwhile, you could try to use a different theme that could handle this strange appearance that you mentioned.
    Also, I would like to suggest you try to use the cellsrenderer callback for a specific column that you want to have dropdown options.
    Please, take a look at this code example:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <title id="Description">In this example is demonstrated how to use the Grid"s CardView mode.</title>
        <link rel="stylesheet" href="../../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />
        <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/jqxwindow.js"></script>
        <script type="text/javascript" src="../../../jqwidgets/jqxgrid.selection.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.edit.js"></script>
        <script type="text/javascript" src="../../../jqwidgets/jqxgrid.sort.js"></script>
        <script type="text/javascript" src="../../../jqwidgets/jqxgrid.columnsresize.js"></script>
        <script type="text/javascript" src="../../../jqwidgets/jqxgrid.edit.js"></script>
        <script type="text/javascript" src="../../../jqwidgets/jqxwindow.js"></script>
        <script type="text/javascript" src="../../../scripts/demos.js"></script>
        <script type="text/javascript">
            $(document).ready(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 < 1000; 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({
                    altrows: true,
                    width: 800,
                    source: dataAdapter,
                    editable: true,
                    sortable: true,
                    selectionmode: "multiplecellsadvanced",
                    cardview: true,
                    cardviewcolumns: [{
                        width: "auto",
                        datafield: "firstname"
                    }, {
                        width: "auto",
                        datafield: "lastname"
                    }, {
                        width: 300,
                        datafield: "productname"
                    }],
    
                    columns: [{
                        text: "First Name",
                        datafield: "firstname",
                        width: 100,
                        cellsrenderer: function() {
                            return "<select name='cars' id='cars'>" +
    				"<option value='volvo'>Volvo</option>" +
    				"<option value='saab'>Saab</option>" +
    				"<option value='mercedes'>Mercedes</option>" +
    				"<option value='audi'>Audi</option>" +
                                "</select>";
                        }
                    }, {
                        text: "Last Name",
                        datafield: "lastname",
                        width: 100,
                        columntype: "dropdownlist"
                    }, {
                        text: "Product",
                        datafield: "productname",
                        width: 180,
                        columntype: "dropdownlist"
                    }, {
                        text: "Quantity",
                        datafield: "quantity",
                        width: 120,
                        cellsalign: "right"
                    }, {
                        text: "Unit Price",
                        datafield: "price",
                        width: 90,
                        cellsalign: "right",
                        cellsformat: "c2"
                    }, {
                        text: "Total",
                        datafield: "total",
                        cellsalign: "right",
                        cellsformat: "c2"
                    }]
                });
    
                $("#jqxbutton").jqxButton();
                $("#jqxbutton").on("click", function() {
                    var cardView = $("#jqxgrid").jqxGrid("cardview");
    
                    $("#jqxgrid").jqxGrid({
                        cardview: !cardView
                    });
                });
            });
        </script>
    </head>
    
    <body></body>
    <div id="jqxgrid"></div>
    <br/>
    <button id="jqxbutton">Switch CardView</button>
    </body>
    
    </html>

    Best Regards,
    Hristo Hristov

    jQWidgets team
    https://www.jqwidgets.com

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

You must be logged in to reply to this topic.