Search code examples
javascripthtmlwebix

Editable Webix Data Table Column Headers


Is it possible to make editable column headers in a webix data table? This code will allow for editing the data in the table but not the headers themselves:

 webix.ui({
    view:"datatable",
    editable:true,
    columns:[
       { id:"title",   header:"Test", fillspace:true, editor:"text"}],
    data:[
        {title:"random"}
    ]
});

Solution

  • There is no built in solution, but it is quite easy to add an external editor

    http://webix.com/snippet/379ee39b

    You can create a separate popup with text editor inside

    webix.ui({ id:"editor", view:"popup", body:{
      view:"form",
      elements:[
        { view:"text", name:"header" },
        { view:"button", value:"Save", click:function(){
          var top = this.getTopParentView();
          top.config.callback( top.getBody().getValues().header);
          top.hide();
        }}
      ]
    }});
    

    And later, use it from header click event

      onHeaderClick:function(id, ev){
        var grid = this;
    
        $$("editor").getBody().setValues({
            header: this.getColumnConfig(id.column).header[0].text
        });
        $$("editor").config.callback = function(value){
          grid.getColumnConfig(id.column).header[0].text = value;
          grid.refreshColumns();
        };
        $$("editor").show(ev);
        $$("editor").getBody().focus();
      }