jQWidgets Forums

jQuery UI Widgets Forums Grid Background color of a Cell

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

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Background color of a Cell #6651

    aquintero
    Member

    It is posble to change the Background color of a Cell depending a condition?
    Thanks in advance!

    Alejandro-

    Background color of a Cell #6665

    Dimitar
    Participant

    Hello Alejandro,

    You can change the background color of cells by changing the CSS of a number of classes:

    jqx-grid-cell – applied to the grid cells.
    jqx-grid-cell-sort – applied to the grid cells in the sort column.
    jqx-grid-group-cell – applied to the cells in a grouping row.
    jqx-grid-details-cell – applied to the cells in a details row.
    jqx-grid-cell-alt – alternating cells style. This is applied to the cells in the alternating rows.
    jqx-grid-cell-pinned – applied to the cells in a pinned column.
    jqx-grid-cell-selected – applied to the cells in a selected row.
    jqx-grid-cell-hover – applied to the cells in a hovered row.

    In the following example, all cells are green, except for the selected cell, which is teal.

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title id='Description'>This example shows how to create a Grid from Array data.</title>
    <link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />
    <style type="text/css">
    <!-- applied to all cells: -->
    .jqx-grid-cell
    {
    background-color: Green;
    }
    <!-- applied to selected cells: -->
    .jqx-grid-cell-selected
    {
    background-color: Teal;
    }
    </style>
    <script type="text/javascript" src="jquery-1.7.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">
    $(document).ready(function () {
    // prepare the data
    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) { }
    });
    $("#jqxgrid").jqxGrid(
    {
    selectionmode: 'singlecell',
    width: 670,
    source: dataAdapter,
    columns: [
    { text: 'First Name', datafield: 'firstname', width: 100 },
    { text: 'Last Name', datafield: 'lastname', width: 100 },
    { text: 'Product', datafield: 'productname', width: 180 },
    { text: 'Quantity', datafield: 'quantity', width: 80, cellsalign: 'right' },
    { text: 'Unit Price', datafield: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2' },
    { text: 'Total', datafield: 'total', width: 100, cellsalign: 'right', cellsformat: 'c2' }
    ]
    });
    var cell = $('#jqxgrid').jqxGrid('selectcell', 2, 'firstname'); // selects a cell
    });
    </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,
    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.