2017-07-28 62 views
0

我已經使用dojo 1.10增強的網格。在這裏,我正在使用onStyleRow事件,我將設計這一行。它在第一次加載時工作得很好,但是當我嘗試執行分頁,排序和過濾時,它不知道記住行並在舊行索引上應用新樣式。例如,如果我在加載時突出顯示了和行。現在,當我對數據進行排序時,數據會發生變化,但在這裏它會將新樣式再次應用到2行和4行,而不管行是否已更改。這是現有代碼中的錯誤嗎?onStyleRow事件不會保留在做排序,過濾或分頁

我做這樣的 -

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;'; 
    }); 

我沒有找到文檔相關的任何事情。有沒有人有這方面的知識?

+0

這裏你正在做row.index因此當你排序時,風格被應用到索引。您必須將該樣式應用於行項目對象 –

回答

1

試試這個

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; 
} 
+1

您能否向我解釋此行的作用var type = store.getValue(item,'col1',null);爲什麼我們在那裏有col1? – shv22

+0

它從商店讀取第1列的值。看看你的data_list,col1的值是'正常','重要'和'重要'。一旦該值等於「正常」,該行將突出顯示。 –

+0

所以在這裏它會一直檢查第一列的值並根據它來應用樣式。所以我可以在我的網格中傳遞每個列的變量,例如1和2,其中1將進行更改,2將使其保持原樣。 – shv22