首页 文章

如何在handsontable中使用handsontable禁用特定列

提问于
浏览
2

如何在handsontable中使用handsontable禁用特定列 . 我想第一列只能编辑其他三列得到禁用 . 我使用readonly为三列但是它不起作用如何禁用....

columns: [
              {
     type:'handsontable',
     handsontable: {

      colHeaders: ['EmployeeNo','EmployeeName','Department','Designation'],
      data: manufacturerData,
      columns:[{},{readOnly: true},
          {
         readOnly: true
            },
          {
        readOnly: true
          }]
         }

         },
         {}]

4 回答

  • 3

    在Project i中,使用这行代码 .

    cells : function(row, col, prop) {
                    var cellProperties = {};
    
                    if (col > 0) {
                        cellProperties.readOnly = true;
                    }
                    else
                    {
                        cellProperties.readOnly = false;
                    }
    
                    return cellProperties;
                }
    

    您可以在给定链接上找到它的工作示例 . 但举个例子是将行设置为只读 . http://handsontable.com/demo/conditional.html

  • 0

    您的代码正常运行 . 请参阅JSFiddle,其方法与您类似 .

    $("#test").handsontable({
        startRows: 1,
        startCols: 1,
        rowHeaders: true,
        colHeaders: true,
        minSpareCols: 0,
        minSpareRows: 0,
        contextMenu: false,
        fillHandle: false,
        outsideClickDeselects: false,
        removeRowPlugin: false,
        currentRowClassName: 'currentRow',
        currentColClassName: 'currentCol',
        columnSorting: true,
        colHeaders: ['Col1','Col2','Col3','Col4'],
        columns: [{},
                  {readOnly: true}, 
                  {readOnly: true},
                  {readOnly: true}]
      });
    

    工作链接:http://jsfiddle.net/rvd61fuy/

    如果您正面临任何其他问题,请告诉我 .

  • 2

    要禁用你可以使单元格/列只读,甚至可以将背景颜色设置为灰色(以产生特殊效果) . 方法即使用readonly的方法:初始化handontable时列声明中为true你使用单元格属性和使用条件来确定是否需要将单元格设置为只在表格渲染时读取的方法,这两种方法似乎都适用于我 . 你需要正确实例化你的HOT,这可能是问题 . 此外,在使用单元格属性时,您不需要使用cellProperties.readOnly = false,因为默认情况下单元格不是只读的,除非您已单独编码 . 如果您需要进一步的帮助,请告诉我 .

  • 0

    还要检查您是否拥有最新版本的handsontable . 我试图在具有不稳定结果的复选框列的单元格上实现readonly时遇到了问题 .

    使用下面的版本解决了我的问题(以下是我在HTML页面中使用的内容)

    <script src="http://docs.handsontable.com/pro/1.9.0/bower_components/handsontable-pro/dist/handsontable.full.min.js"></script>
    <link type="text/css" rel="stylesheet" href="http://docs.handsontable.com/pro/1.9.0/bower_components/handsontable-pro/dist/handsontable.full.min.css">
    

相关问题