我想在jqx网格小部件中渲染具有重复值的单元格。例如;
我想标记具有重复值的绿色边框的数字单元格。在此示例中,将标记第一行和第二行。
有一个带有这些参数的单元格渲染器功能;
var cellsrenderer = function (row, columnfield, value, defaulthtml, columnproperties) { }
我该怎么做?
答案 0 :(得分:1)
作为下面例子的参考,我采用了例子' angularjs-grid-with-jqx-settings.htm'来自jqwidgets 4.0.0并添加了cellsrenderer。对不起,如果你不使用angularjs,但它是模拟的,如果你使用普通的jquery解决方案。
<!DOCTYPE html>
<html ng-app="demoApp">
<head>
<title id="Description">AngularJS Grid directive settings</title>
<link rel="stylesheet" type="text/css" href="../../../jqwidgets/styles/jqx.base.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/jqxcheckbox.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" src="../../../jqwidgets/jqxmenu.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxscrollbar.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxgrid.sort.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxangular.js"></script>
<script type="text/javascript" src="../../../scripts/demos.js"></script>
<script type="text/javascript">
var demoApp = angular.module("demoApp", ["jqwidgets"]);
demoApp.controller("demoController", function ($scope) {
// Grid data.
var data = new Array();
var firstNames = ["Nancy", "Andrew", "Janet", "Margaret", "Steven", "Michael", "Robert", "Laura", "Anne"];
var lastNames = ["Davolio", "Fuller", "Leverling", "Peacock", "Buchanan", "Suyama", "King", "Callahan", "Dodsworth"];
var titles = ["Sales Representative", "Vice President, Sales", "Sales Representative", "Sales Representative", "Sales Manager", "Sales Representative", "Sales Representative", "Inside Sales Coordinator", "Sales Representative"];
var city = ["Seattle", "Tacoma", "Kirkland", "Redmond", "London", "London", "London", "Seattle", "London"];
var country = ["USA", "USA", "USA", "USA", "UK", "UK", "UK", "USA", "UK"];
for (var i = 0; i < firstNames.length; i++) {
var row = {};
row["firstname"] = firstNames[i];
row["lastname"] = lastNames[i];
row["title"] = titles[i];
row["city"] = city[i];
row["country"] = country[i];
data[i] = row;
}
$scope.people = data;
var renderCity = function (row, columnfield, value, defaulthtml, columnproperties) {
var rows = $scope.settings.apply('getrows');
var duplicates = false;
rows.forEach(function (record, i) {
if (i != row && record.city == value)
duplicates = true;
});
if (duplicates) {
defaulthtml = defaulthtml.substring(0, defaulthtml.indexOf(">")).replace('style="', 'style="border-color: green; border-style: solid; border: 2px ');
defaulthtml += '">' + value + '</div>';
}
return defaulthtml;
};
$scope.settings =
{
altrows: true,
width: 800,
height: 400,
sortable: true,
source: $scope.people,
columns: [
{text: 'First Name', datafield: 'firstname', width: 150},
{text: 'Last Name', datafield: 'lastname', width: 150},
{text: 'Title', datafield: 'title', width: 150},
{text: 'City', datafield: 'city', width: 150, cellsrenderer: renderCity},
{text: 'Country', datafield: 'country'}
],
}
});
</script>
</head>
<body>
<div ng-controller="demoController">
<jqx-grid jqx-settings="settings"></jqx-grid>
</div>
</body>
</html>
我希望这有帮助!