2015-04-08 20 views

回答

0

這是我從KendoGridBinderEx改編的版本,因爲我想要一個數據綁定函數,它不僅可以處理空的錯誤情況。我已經修改它,主要適合你正在掙扎的東西。當我的數據源發生錯誤時,我會將它們從我傳入函數本身的事件中讀出來,這就是爲什麼你看到'e'作爲參數引用但未被使用。

function DisplayNoResultsFound(evt) { 
    var grid = evt.sender.element; 
    //Only do this if you can properly find the grid 
    if (grid.data("kendoGrid") == undefined) { 
     return; 
    } 

    // Get the number of Columns in the grid 
    var dataSource = grid.data("kendoGrid").dataSource; 
    var colCount = grid.find('.k-grid-header colgroup > col').length; 

    //Check for an empty datasource 
    if (dataSource._view.length == 0) { 
     //Clear the grid 
     //you may or may not need this depending on how your datasource returns 
     grid.find('.k-grid-content tbody').empty(); 

     //Add the no result row 
     grid.find('.k-grid-content tbody') 
     .append('<tr class="kendo-data-row"><td colspan="' + colCount + '" style="text-align:center" class="k-state-error"><b>No Results Found</b></td></tr>'); 
    } 

    // Get visible row count 
    var rowCount = grid.find('.k-grid-content tbody tr').length; 

    // If the row count is less that the page size add in the number of missing rows 
    if (rowCount < dataSource._take) { 
     var addRows = dataSource._take - rowCount; 
     for (var i = 0; i < addRows; i++) { 
      grid.find('.k-grid-content tbody').append('<tr class="kendo-data-row"><td>&nbsp;</td></tr>'); 
     } 
    } 
} 

編輯:這裏有一個JSFiddle example

+0

感謝您的答覆。但是這個也沒有包括劍橋網格:/。對於不可分割的劍道網格工作良好。你能分享JSFiddle嗎?? –

+0

我已經添加了一個指向服務器端Kendo OData源的JSFiddle。如果您嘗試過濾訂單ID = 0,則應該得到「未找到結果」,類似地,如果添加任意數量的組,您仍應該看到該消息。 –

+0

非常感謝Brian。這工作正常。但我想要的是一個可分組的kendo網格,看起來像這樣: http://docs.telerik.com/kendo-ui/web/grid/grid6_1.png 這是根據姓氏分組。 我在爲這種網格添加「空文本」時遇到了問題。 :( –

相關問題