EasyUI Forum
November 06, 2025, 01:33:58 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to dynamically set datagrid/treegrid editor  (Read 16894 times)
pmjenn
Newbie
*
Posts: 9


View Profile
« on: January 03, 2013, 05:32:35 AM »

I am using minimal markup in my HTML to define a treegrid.

    <div id="treePanelContent">
       <table id="myTree"></table>
    </div>

I initialize the treegrid with javascript, here's a snippet that shows columns definitions without editors.

$('#myTree').treegrid({
   ...,
   idField:'id',
   treeField:'name',
   frozenColumns:[[
                   {title:'Id',field:'id',width:100,
                     formatter:function(value){
                   return '<span style="color:red">'+value+'</span>';
                   },
                    editor: 'text'
               }
   ]],
   columns:[[
      {field:'description',title:'Name',width:250,rowspan:2},
      {field:'type',title:'Type',width:75,rowspan:2},
      {field:'startDate',title:'Start Date',width:75,rowspan:2},
      {field:'endDate',title:'End Date',width:75,rowspan:2},
   ]],
   ...,
});

The "description" column is special because editing is dependent on the node type in the tree. The node type can be defined as "text", which would use {editor : {type: 'text'}}, or "select", which would use {editor: {type: 'combox', options: { ...}}. The node type is defined in a context menu which allows the user to select which type of node to add to the tree.

How can I set the editor dynamically after the treegrid has been initialized?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: January 03, 2013, 08:26:15 PM »

When begin to edit a row, the 'onBeforeEdit' event handler can be used to change the editor type for a specify column.
Code:
$('#myTree').treegrid({
onBeforeEdit:function(row){
var col = $(this).treegrid('getColumnOption','description');
if (row.type == 'text'){
col.editor = 'text';
} else if (row.type == 'select'){
col.editor = {
type: 'combobox',
options:{
//...
}
}
}
}
});
Logged
pmjenn
Newbie
*
Posts: 9


View Profile
« Reply #2 on: January 24, 2013, 06:02:52 PM »

Forgot to mention that your suggestion worked great. Thanks for the help!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!