2012-02-08 79 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); 
    });