gpt4 book ai didi

javascript - onStyleRow 事件不会保留进行排序、过滤或分页

转载 作者:行者123 更新时间:2023-12-03 03:46:10 24 4
gpt4 key购买 nike

我使用了dojo 1.10增强网格。在这里,我使用 onStyleRow 事件来设置行的样式。它在第一次加载时工作得很好,但是当我尝试进行分页、排序和过滤时,它不知道记住行并在旧行索引上应用新样式。例如,如果我在加载时突出显示 24 行。现在,当我进行排序时,行数据将会更改,但这里它会再次将新样式应用于 2 行和 4 行,无论行如何更改。这是现有代码中的错误吗?

我正在这样做 -

 dojo.connect(mygrid, 'onStyleRow', this, function(row) {
if (fixedDataItems[row.index] == '1' && hideFixesVisibility == 'Editable') //some condition
row.customStyles += 'background-color: blue !important;';
else
row.customStyles += 'color: black !important;';
});

我在文档中没有找到任何与之相关的内容。有人了解这方面的知识吗?

最佳答案

试试这个

http://jsfiddle.net/bnqkodup/374/

HTML

<div id="container" class="claro">
<div id="gridDiv"></div>
</div>

JS

dojo.require("dojox.grid.EnhancedGrid");
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojo.on");

dojo.ready(function (on) {
/*set up data store*/
var data = {
identifier: 'id',
items: []
};
var data_list = [{
col1: "normal",
col2: false,
col3: 'But are not followed by two hexadecimal',
col4: 29.91
}, {
col1: "important",
col2: false,
col3: 'Because a % sign always indicates',
col4: 9.33
}, {
col1: "important",
col2: false,
col3: 'Signs can be selectively',
col4: 19.34
}];
var rows = 60;
for (var i = 0, l = data_list.length; i < rows; i++) {
data.items.push(dojo.mixin({
id: i + 1
}, data_list[i % l]));
}
var store = new dojo.data.ItemFileWriteStore({
data: data
});
function formatLink(value){
return '<a href="#">'+value+'</a>';
}
/*set up layout*/
var layout = [
[{
'name': 'Column 1',
'field': 'id',
formatter: formatLink

}, {
'name': 'Column 2',
'field': 'col2'
}, {
'name': 'Column 3',
'field': 'col3',
'width': '230px'
}, {
'name': 'Column 4',
'field': 'col4',
'width': '230px'
}]
];

/*create a new grid:*/
var grid = new dojox.grid.EnhancedGrid({
id: 'grid',
store: store,
structure: layout,
rowSelector: '20px'
},
document.createElement('div'));

/*append the new grid to the div*/
dojo.byId("gridDiv").appendChild(grid.domNode);

/*Call startup() to render the grid*/
grid.startup();

//dojo.on(grid,"CellClick",function(evt){

/* <=search for the column here */
//var idx = evt.cellIndex;
//var cellNode = evt.cellNode;
//if(cellNode){
//cellNode.style.backgroundColor = "green";
// }
//if(evt.cellIndex==1){
//this.set('style','background-color:red;');
// }
// });
dojo.connect(grid, 'onStyleRow', this, function(row) {
var item = grid.getItem(row.index);
if(item){
//console.log(store);
var type = store.getValue(item,'col1',null);

if(type == "normal"){
row.customStyles += "color:red;";
//row.customClasses += " dismissed";
}
}
});
});

CSS

@import"../lib/dojo/resources/dojo.css";
@import"../lib/dijit/themes/claro/claro.css";
@import"../lib/dojox/grid/enhanced/resources/claro/EnhancedGrid.css";
@import"../lib/dojox/grid/enhanced/resources/EnhancedGrid_rtl.css";

/*Grid need a explicit width/height by default*/
#grid {
width: 1110px;
height: 494px;
color: #000000;
}

关于javascript - onStyleRow 事件不会保留进行排序、过滤或分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45380661/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com