【问题标题】:Slickgrid - Change Editor of Single Cell, and not Entire ColumnSlickgrid - 更改单个单元格的编辑器,而不是整个列
【发布时间】:2015-01-07 11:06:25
【问题描述】:

这是场景:

  • 有多行可选数据
  • 一列 (#1) 具有带有两个选项的下拉编辑器
  • 下一列 (#2) 可以有文本编辑器或下拉编辑器 - 取决于在第一个下拉列表中选择的选项,请参见示例:

    _________Column #1_________|_________Column #2_________

    1     select opt 1      |      *dropdown editor*    

    2     select opt 1      |      *dropdown editor*    

    3     select opt 1      |      *dropdown editor*    

    4     select opt 2      |      *text editor*        

    5     select opt 1      |      *dropdown editor*    

    6     select opt 1      |      *dropdown editor*    

是否甚至可以根据另一个单元格的输入/更改来更改单个单元格的编辑器?似乎您无法在单元格级别更改编辑器,而只能在列级别更改。

非常感谢任何帮助,我们已经为此花费了很多时间;并没有找到解决方案甚至类似的问题。谢谢

更新

这可能越来越接近了:

var currentRowIndex = object.grid.getActiveCell().row,
    nextCellIndex = object.grid.getActiveCell().cell + 1;
object.grid.setActiveCell(currentRowIndex, nextCellIndex);
object.grid.editActiveCell(this.editors.textEditor);

但这并不能确保编辑器仍然存在;例如^一个文本编辑器。更改第一列 (#1) 中的值并启用上述第 2 列中的文本编辑器时 - 在此编辑发生后 - 原始编辑器仍在第 2 列中。

我希望编辑器保持不变 - 但找不到如何在单元格级别而不是列级别执行此操作。谢谢

【问题讨论】:

    标签: javascript jquery slickgrid


    【解决方案1】:

    浏览与检索编辑器相关的the sourcegetEditor第 1381 行)显示有几个不同的选项可用。

    鉴于您需要行内的不同列值,我将使用列元数据来解决问题,因为它接收 rowIndex 作为参数。

    var viewModel = {options: ['LongText', 'Text', 'Checkbox']}
     
    function apply() {
        var grid, data = [];
            
        var options = {
            editable: true,
            enableCellNavigation: true,
            asyncEditorLoading: false,
            autoEdit: true,
            forcefitColumns: false
             
        };
    
        var columns = [{
            id: "data",
            name: "Editor Type",
            field: "type",
            width: 120,
            cssClass: "cell-title" ,
            formatter: function(row){ 
                var key = 'input'+row;
                
                if(!viewModel[key]){
                  viewModel[key] = ko.observable();
                  viewModel[key].subscribe(function(nv){
                  
                  data[row].type = nv
                })
               }
                 
                setTimeout(function(){ ko.applyBindings(viewModel, document.getElementById(key))  }, 250);
                return '<select id="'+key+'", data-bind="options: options, value: '+key+'"></select>'
            }
           },
           {
            id: "other",
            name: "Other",
            field: "other",
            width: 120,
            cssClass: "cell-title",
             
        }];
    
        for (var i = 0; i < 5; i++) {
            var d = (data[i] = {});
    
            d["type"] =  "";
            d["other"] = "Default " + i;
        }
    
        grid = new Slick.Grid("#myGrid", data, columns, options);
        //ko.applyBindings(viewModel)
    
        data.getItemMetadata=function(row){
        
            var rowData = data[row]
            //console.log(rowData)
            var metaData = {columns:{other: {}}}
            metaData.columns.other.editor = Slick.Editors[rowData.type]
             
            return metaData
        }
       
    }
    
    apply()
    <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
    <link rel="stylesheet" type="text/css" href="http://JLynch7.github.io/SlickGrid/slick.grid.css">
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <script src="http://code.jquery.com/ui/1.11.0/jquery-ui.min.js"></script>
    <script src="http://JLynch7.github.io/SlickGrid/slick.dataview.js"></script>
    <script src='http://mleibman.github.io/SlickGrid/lib/jquery.event.drag-2.2.js'></script>
    <script src='http://JLynch7.github.io/SlickGrid/slick.core.js'></script>
    <script src='http://JLynch7.github.io/SlickGrid/slick.grid.js'></script>
    <script src='http://JLynch7.github.io/SlickGrid/slick.formatters.js'></script>
    <script src='http://JLynch7.github.io/SlickGrid/slick.editors.js'></script>
    
    <div id='container'>
        <div id="myGrid" style="width:600px;height:300px;"></div>
    </div>

    【讨论】:

      猜你喜欢
      • 2012-08-18
      • 2017-03-24
      • 2013-03-05
      • 2020-02-20
      • 2018-12-13
      • 1970-01-01
      • 1970-01-01
      • 2015-02-04
      • 1970-01-01
      相关资源
      最近更新 更多