2013-10-23 50 views
0

我在網上編輯並編輯列顯示爲下拉列表。當我選擇任何項目然後進行排序時,我將[對象對象]作爲單元格的值。截至目前,我已經編寫了代碼將其刪除,如下所示。kendo ui網格在編輯時排序錯誤

dataBound: function(e) { 
       if(e.sender != null) { 
        var container = e.sender; 
        var rows = container.tbody[0].childNodes; 
        $.each(rows, function (i, val) { 
         var cols = rows[i].childNodes; 
         $.each(cols, function (k, value) { 
          if(cols[k].innerText == "[object Object]") 
           cols[k].innerText = ""; 
         }); 
        }); 
       } 
      } 

有人有更好的解決方案嗎?

回答

0

我通過在點擊事件上調用網格標題修復了問題,並在其中檢查該列是否可排序,如果是,則調用網格的cancelChanges()方法。

$(function() { 
      var gr = $('#grid').data().kendoGrid; 
      gr.thead.on('click', function (e) { 
       if((e.target && e.target.href) || (e.target.cellIndex && gr.columns[e.target.cellIndex].sortable)) 
        gr.cancelChanges(); 
      }); 
     }); 

此外,添加排序屬性到網格中的字段像下面甚至sortable = true是默認值。

columns: [ 
          "ProductName", 
          { field: "UnitPrice", title: "Unit Price", sortable:true, format: "{0:c}", width: "100px" }, 
          { field: "UnitsInStock", title:"Units In Stock", sortable:true, width: "100px" }, 
          { field: "Discontinued", sortable:false, width: "100px" }, 
          { command: ["edit", "destroy"], title: " ", sortable:false, width: "172px" }]