2012-02-08 80 views

回答

0

SlickGrid不支持。

+0

好的。以及用紅色背景製作無效單元格(添加新行之後)呢?也許有些解決方法可以幫助我? – 2012-02-10 10:43:26

+1

在onAddNewRow處理程序中,您可以驗證所有單元格併爲有問題的單元格提供「無效」CSS類(請參閱https://github.com/mleibman/SlickGrid/wiki/Providing-data-to-the-grid) 。 – Tin 2012-02-10 16:56:48

5

這是一個工作片段。它不會停止添加行,但會在新行上運行所有驗證,並強制用戶輸入所有缺少的值。

首先定義validateRow功能(理想情況下,應該在SlickGrid命名空間放):

function validateRow(grid, rowIdx) { 
    $.each(grid.getColumns(), function(colIdx, column) { 
     // iterate through editable cells 
     var item = grid.getDataItem(rowIdx); 

     if (column.editor && column.validator) { 
      var validationResults = column.validator(item[column.field]); 
      if (!validationResults.valid) { 
       // show editor 
       grid.gotoCell(rowIdx, colIdx, true); 

       // validate (it will fail) 
       grid.getEditorLock().commitCurrentEdit(); 

       // stop iteration 
       return false; 
      } 
     } 
    }); 
} 

然後調用它在onAddNewRow結合FUNC(或者,如果你不使用數據視圖中添加項目陣列後):

grid.onAddNewRow.subscribe(function (e, args) { 
     dataView.addItem($.extend({ 
      id: dataView.getLength() 
     }, args.item)); 
     validateRow(args.grid, args.grid.getActiveCell().row); 
    });