【问题标题】:How to change background color of the row after changing its value?更改值后如何更改行的背景颜色?
【发布时间】:2016-03-15 00:53:10
【问题描述】:

如何为值已更改的行设置自定义 CSS(例如background-color:red)样式?

我正在使用 Webix,下面的函数运行良好,但我不确定是否有方便的 CSS 实现:

  on:{
    onAfterEditStop:function(state,editor){      
      if(state.old != state.value){
        webix.message("Row "+editor.row+" has been changed")
      }        
    }}

完整的 sn-p 是 here。提前致谢!

【问题讨论】:

    标签: javascript css datatable webix


    【解决方案1】:

    Example

    说明: 只需将函数 this.addRowCss 添加到您的事件中。文档可以在这里找到:http://docs.webix.com/api__ui.datatable_addrowcss.html

    如果您希望这是临时的,只需在事件中添加一个计时器,然后在计时器到期时执行 this.removeRowCss 以删除此颜色。如果您需要示例,请询问。


    代码:

    var data = [
        { id:1, value:"Aa"},
        { id:2, value:"Bb"},
        { id:3, value:"Cc"},
        { id:4, value:"Dd"},
        { id:5, value:"Ee"},
        { id:6, value:"Ff"}
    ];
    
    
    webix.ui({
      id:"table", view : "datatable", editable:true, 
      columns : [ 
        { id : "id", header : "", fillspace:0.1 }, 
        { id : "value", header : "Editable", editor : "text",  fillspace : 0.7 }
      ],
      data:data,  
      on:{
        onAfterEditStop:function(state,editor){      
          if(state.old != state.value){
            //this has to assign a css class name
            this.addRowCss(editor.row, "test");
            webix.message("Row "+editor.row+" has been changed")
          }        
        }}
      });
    

    Example with timer for removing color

    var data = [
        { id:1, value:"Aa"},
        { id:2, value:"Bb"},
        { id:3, value:"Cc"},
        { id:4, value:"Dd"},
        { id:5, value:"Ee"},
        { id:6, value:"Ff"}
    ];
    
    webix.ui({
      id:"table", view : "datatable", editable:true, 
      columns : [ 
        { id : "id", header : "", fillspace:0.1 }, 
        { id : "value", header : "Editable", editor : "text",  fillspace : 0.7 }
      ],
      data:data,  
      on:{
        onAfterEditStop:function(state, editor){
          if(state.old != state.value){
            var that = this;
            webix.message("Row "+editor.row+" has been changed")
            // 1500 is the number of milliseconds until color is changed back
            toggleRowCss(that, editor.row, "test", 1500);
          }        
        }
      }
    });
    
    function toggleRowCss(table, row, cssClass, timeout){
      //this has to assign a css class name
      table.addRowCss(row, cssClass);
      setTimeout(function(){ table.removeRowCss(row, cssClass); }, timeout);
    }
    

    【讨论】:

    • 哇,谢谢!你能提供一个计时器的例子吗?好像我不完全理解如何在 Webix 中做这样的事情。
    • @letItReign 计时器示例添加
    猜你喜欢
    • 2011-11-11
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    相关资源
    最近更新 更多