UNPKG

jqwidgets-framework

Version:

jQWidgets is an advanced Angular, Vue, Blazor, React, Web Components, jquery, ASP .NET MVC, Custom Elements and HTML5 UI framework.

140 lines (134 loc) 6.26 kB
<!DOCTYPE html> <html ng-app="demoApp" lang="en"> <head> <title id='Description'>The sample illustrates how to add custom CSS styles to Grid cells under specific conditions.</title> <meta name="description" content="AngularJS DataTable with conditional formatting." /> <link rel="stylesheet" href="../../../jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="../../../scripts/angular.min.js"></script> <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/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/jqxdatatable.js"></script> <script type="text/javascript" src="../../../scripts/demos.js"></script><script type="text/javascript" src="../../../jqwidgets/jqxangular.js"></script> <script type="text/javascript"> var demoApp = angular.module("demoApp", ["jqwidgets"]); demoApp.controller("demoController", function ($scope) { var url = "../../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 cellClass = function (row, dataField, cellText, rowData) { var cellValue = rowData[dataField]; switch (dataField) { case "QuantityPerUnit": if (cellValue < 11) { return "min"; } if (cellValue < 14) { return "minavg"; } if (cellValue < 50) { return "avg"; } return "max"; case "UnitPrice": if (cellValue < 20) { return "min"; } if (cellValue < 30) { return "minavg"; } if (cellValue < 50) { return "avg"; } return "max"; case "UnitsInStock": if (cellValue < 20) { return "min"; } if (cellValue < 30) { return "minavg"; } if (cellValue < 50) { return "avg"; } return "max"; } } var dataAdapter = new $.jqx.dataAdapter(source, { downloadComplete: function (data, status, xhr) { }, loadComplete: function (data) { }, loadError: function (xhr, status, error) { } }); // initialize AngularJS DataTable $scope.gridSettings = { source: dataAdapter, pageable: true, sortable: true, altRows: true, selectionMode: 'none', enableHover: false, columns: [ { text: 'Product Name', dataField: 'ProductName', width: 200 }, { text: 'Quantity per Unit', dataField: 'QuantityPerUnit', cellClassName: cellClass, cellsAlign: 'right', align: 'right', width: 200 }, { text: 'Unit Price', dataField: 'UnitPrice', align: 'right', cellClassName: cellClass, cellsAlign: 'right', cellsformat: 'c2', width: 200 }, { text: 'Units In Stock', dataField: 'UnitsInStock', cellsAlign: 'right', width: 250, align: 'right', cellClassName: cellClass} ] }; }); </script> </head> <body ng-controller="demoController"> <style> .max { color: black\9; background-color: #63be7b\9; } .avg { color: black\9; background-color: #f8e984\9; } .minavg { color: black\9; background-color: #f9806f\9; } .min { color: black\9; background-color: #f8696b\9; } .max:not(.jqx-data-table-cell-hover):not(.jqx-data-table-cell-selected), .jqx-widget .max:not(.jqx-data-table-cell-hover):not(.jqx-data-table-cell-selected) { color: black; background-color: #63be7b; } .avg:not(.jqx-data-table-cell-hover):not(.jqx-data-table-cell-selected), .jqx-widget .avg:not(.jqx-data-table-cell-hover):not(.jqx-data-table-cell-selected) { color: black; background-color: #f8e984; } .minavg:not(.jqx-data-table-cell-hover):not(.jqx-data-table-cell-selected), .jqx-widget .minavg:not(.jqx-data-table-cell-hover):not(.jqx-data-table-cell-selected) { color: black; background-color: #f9806f; } .min:not(.jqx-data-table-cell-hover):not(.jqx-data-table-cell-selected), .jqx-widget .min:not(.jqx-data-table-cell-hover):not(.jqx-data-table-cell-selected) { color: black; background-color: #f8696b; } </style> <jqx-data-table jqx-settings="gridSettings"> </div> </body> </html>