jQuery UI Widgets Forums Grid change row color after render

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

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • change row color after render #58885

    aldo86
    Participant

    Hi,
    I’ve to change the background of single row by id after render. How can i do it?

    Best regards

    change row color after render #58893

    aldo86
    Participant

    I know cellsrenderer : function (row, column, value, defaultHtml) but i need to trigger/refresh it when i’ve got the new value.

    change row color after render #58897

    Nadezhda
    Participant

    Hello aldo86,

    Here is an example:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <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/jqxcheckbox.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.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.sort.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.pager.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.edit.js"></script>
        <script type="text/javascript" src="../../scripts/demos.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var url = "../demos/sampledata/products.xml";
                // prepare the data
                var source =
                {
                    datatype: "xml",
                    datafields: [
                        { name: 'ProductName', type: 'string' },
                        { name: 'QuantityPerUnit', type: 'int' },
                        { name: 'UnitPrice', type: 'float' },
                        { name: 'UnitsInStock', type: 'float' },
                        { name: 'Discontinued', type: 'bool' }
                    ],
                    root: "Products",
                    record: "Product",
                    id: 'ProductID',
                    url: url
                };
    
                var highlightedRow = 1;
                var cellclass = function (row, columnfield, value) {
                    var id = $('#jqxgrid').jqxGrid('getrowid', row);
                    if (id == highlightedRow) {
                        return 'red';
                    }
                }
                $("#jqxbutton").click(function () {
                    highlightedRow = $("#inputField").val();
                    $('#jqxgrid').jqxGrid('refresh');
    
                })
                var dataAdapter = new $.jqx.dataAdapter(source, {
                    downloadComplete: function (data, status, xhr) { },
                    loadComplete: function (data) { },
                    loadError: function (xhr, status, error) { }
                });
                // initialize jqxGrid
                $("#jqxgrid").jqxGrid(
                {
                    width: 850,
                    source: dataAdapter,
                    pageable: true,
                    autoheight: true,
                    sortable: true,
                    altrows: true,
                    enabletooltips: true,
                    editable: true,
                    selectionmode: 'multiplecellsadvanced',
                    columns: [
                      { text: 'Product Name', columngroup: 'ProductDetails', datafield: 'ProductName', width: 250, cellclassname: cellclass },
                      { text: 'Quantity per Unit', columngroup: 'ProductDetails', datafield: 'QuantityPerUnit', cellsalign: 'right', align: 'right', width: 200, cellclassname: cellclass },
                      { text: 'Unit Price', columngroup: 'ProductDetails', datafield: 'UnitPrice', align: 'right', cellsalign: 'right', cellsformat: 'c2', width: 200, cellclassname: cellclass },
                      { text: 'Units In Stock', datafield: 'UnitsInStock', cellsalign: 'right', width: 100, cellclassname: cellclass },
                      { text: 'Discontinued', columntype: 'checkbox', datafield: 'Discontinued', cellclassname: cellclass }
                    ],
                    columngroups: [
                        { text: 'Product Details', align: 'center', name: 'ProductDetails' }
                    ]
                });
            });
        </script>
        <style>
            .red {
                background-color: red;
            }
        </style>
    </head>
    <body>
        <div id='jqxWidget' style="font-size: 13px; font-family: Verdana;">
            <div id="jqxgrid">
            </div>
        </div>
        <input type="text" style="margin: 10px;" id="inputField" value="1" />
        <input type="button" style="margin: 10px;" id="jqxbutton" value="change highlighted row" />
    </body>
    </html>

    I hope it would be helpful.

    Best Regards,
    Nadezhda

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

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

You must be logged in to reply to this topic.