2

3 番目と 4 番目のセル (TD) の値を取り出して比較する方法がわかりません。それらが同じ値を持っている場合、cssClass を行に追加したいと思います。それを行う方法もわかりません:

 $("#grid tr").each(function() {


           var theValueInCell3 = ?   // how to get the cell's value?
           var theValueInCell4 = ?   // how to get the cell's value

           if (theValueInCell3 == theValueInCell4)
             {

                  //pseudo-code to add a cssClass to the row
                  $(this).addClass('foo');
             }

    });

編集:これは@Pechkaの提案に従おうとする私の最新の試みです:

   .
   .
   .
   if (grid != null) {
    grid.dataSource.data(parsedData);        
    setTimeout(StyleRows, 500);
  }


  function StyleRows() {

      var grid = $('#grid').data('kendoGrid');
      $("#grid tr").each(function () { 
         var dataItem = grid.dataItem(this);   // dataItem is undefined
         if (dataItem.PropA == dataItem.PropB) {
            $(this).addClass('foo');
        }

    });
   }

エラーは、dataItem未定義です。

4

2 に答える 2

5

こんにちは、その行に関連する基になるモデルを取得するために使用されるdataItemメソッドを使用することをお勧めします。例えば

var grid = $('#grid').data().kendoGrid;
$('#grid tr').each(function(){
     var dataItem = grid.dataItem(this);
     if(dataItem.PropName == dataItem.SomeOtherProp){
          $(this).addClass('foo');
     }
})
于 2012-12-17T19:10:36.857 に答える
2

使用している場合はKendoGrid、おそらくそれにDataSourceバインドされています。したがって、各列には実際に名前があり、バインドされた値から値を取得できます。

jQuery パスに移動したい場合 (ドラフト コードからのように) 、 n 番目のセルまたはテーブル行nth-childへの参照を取得できるセレクターを調べることができます。

$("tr", "#grid").each(function (idx, elem) {
    var theValueInCell3 = $(":nth-child(3)", elem).html();
    var theValueInCell4 = $(":nth-child(4)", elem).html();

    //pseudo-code to add a cssClass to the row
    if (theValueInCell3 === theValueInCell4) {
        $(this).addClass('foo');
    }
});

最後に、KendoGrid行をフォーマットするために、 Grid Row Templateを調べてください。

于 2012-12-17T18:00:05.133 に答える