如何限制对数据表行的选择?

How to restrict selection on the datatable row?

我想禁用数据表行。在这种情况下,我看到两个必需的步骤:

我已经通过相应的 Webix 方法成功完成了第一步:

function disableRow(table, row){
  table.addRowCss(row, "disabled-row")
};

webix.ui({
  view:"datatable",
  id:"mytest",
  ...
}); 

disableRow($$("mytest"), 2)

http://webix.com/snippet/e47b4257

但是如何限制这一行的选择呢?谢谢

使用 !important 覆盖 table 样式:

<style>
 .disabled-row {
   background-color: #ddd !important;
   color: #aaa !important;
 }
</style>

http://webix.com/snippet/1a3569c6

我找到了你要找的答案here

There's no disabled property for rows, but you can use onBeforeSelect and onBeforeEditStart events to prevent related actions on the particular row:

上面 linked 页面上有一个 link 到 this 的片段,可以满足您的需求。

webix.ui({
    view:"datatable", autoConfig:true, editable:true, data:grid_data,
        on:{
            onBeforeEditStart:function(id){
                if (id.row == 2 ) return false
            },
            onBeforeSelect:function(id){
                if (id.row == 2 ) return false
            } 
        }
});

似乎没有内置的方法来禁用一行。我确实遇到了 this 可能有帮助的片段

我之后尝试以编程方式选择该行,但它不允许您这样做。

webix.ui({
  view:"datatable", id:"abc",autoConfig:true, editable:true, data:grid_data,
  on:{
    onBeforeEditStart:function(id){
      if (id.row == 2 ) return false
    },
    onBeforeSelect:function(id){
     if (id.row == 2 ) return false
    }
  }
});

$$("abc").select(2);
alert($$("abc").getSelectedId())
$$("abc").select(3);
alert($$("abc").getSelectedId())

要禁用 webix 提供的任何功能,您可以覆盖其事件并处理相同的事件: 想停止对任何特定列、行或单元格的选择,您可以覆盖 onBeforeSelect 和 return false 对于特定的 row/column/cell.

一切都有事件,即 onBeforeSelect,onAfterSelect,onBeforeEditStop, onAfterEditStop