しばらく遊んで、この「解決策」を思いつきました。残念ながら、それはあなたが望む正確な解決策ではありません。解決後に問題を説明します。
1.)content
列定義のプロパティを使用する必要があります。
content: A function that takes row data and expects a string or a jQuery object to customize the cell.
2.) すべての列でコンテンツを使用します。
{
field: 'vin',
headerText: 'Vin',
sortable: true,
content: function(rowData) {
return contentFunc(rowData, 'vin');
}
}
3.) を受け取り、rowData
この要素を強調表示する必要があるかどうかをチェックする関数を作成します。
function contentFunc(rowData, prop) {
var result = $("<span />").html(rowData[prop]);
if (rowData.highlight) {
result.css('background', 'red');
}
return result;
}
問題:作成
したものだけを「ハイライト」span
できます。もtd
もtr
. なんで?span
関数が jQuery オブジェクトを返すときに が挿入されるためです。td
それ以前は、またはにアクセスできませんtr
。後でそれを行うためにいくつかのコールバックを追加できるかどうかはわかりません。(ハックは、ビューポート全体にまたがって関数を呼び出すマウスオーバーになりますが、それは私見のハックです。)
これをすべてまとめてください:
<div id="tbllocal"></div>
var ourJson1 = [{
'highlight': false,
'brand': 'Volkswagen',
'year': 2012,
'color': 'White',
'vin': 'dsad231ff'
}, {
'highlight': true,
'brand': 'Audi',
'year': 2011,
'color': 'Black',
'vin': 'gwregre345'
}, {
'highlight': false,
'brand': 'Renault',
'year': 2005,
'color': 'Gray',
'vin': 'h354htr'
}, {
'highlight': false,
'brand': 'Bmw',
'year': 2003,
'color': 'Blue',
'vin': 'j6w54qgh'
}, {
'highlight': false,
'brand': 'Mercedes',
'year': 1995,
'color': 'White',
'vin': 'hrtwy34'
}, {
'highlight': false,
'brand': 'Opel',
'year': 2005,
'color': 'Black',
'vin': 'jejtyj'
}, {
'highlight': true,
'brand': 'Honda',
'year': 2012,
'color': 'Yellow',
'vin': 'g43gr'
}, {
'highlight': false,
'brand': 'Chevrolet',
'year': 2013,
'color': 'White',
'vin': 'greg34'
}, {
'highlight': false,
'brand': 'Opel',
'year': 2000,
'color': 'Black',
'vin': 'h54hw5'
}, {
'highlight': false,
'brand': 'Mazda',
'year': 2013,
'color': 'Red',
'vin': '245t2s'
}];
$('#tbllocal').puidatatable({
caption: 'Local Datasource',
columns: [{
field: 'vin',
headerText: 'Vin',
sortable: true,
content: function(rowData) {
return contentFunc(rowData, 'vin');
}
}, {
field: 'brand',
headerText: 'Brand',
sortable: true,
content: function(rowData) {
return contentFunc(rowData, 'brand');
}
}, {
field: 'year',
headerText: 'Year',
sortable: true,
content: function(rowData) {
return contentFunc(rowData, 'year');
}
}, {
field: 'color',
headerText: 'Color',
sortable: true,
content: function(rowData) {
return contentFunc(rowData, 'color');
}
}],
datasource: ourJson1,
content: contentFunc
});
function contentFunc(rowData, prop) {
var result = $("<span />").html(rowData[prop]);
if (rowData.highlight) {
result.css('background', 'red');
}
return result;
}
ここにフィドルがあります