EasyUI Forum
July 04, 2024, 03:32:51 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Change editor edatagrid [SOLVED]  (Read 7744 times)
finzaiko
Newbie
*
Posts: 44


View Profile
« on: February 26, 2016, 04:18:14 AM »

How change editor in edatagrid depent on other value
Code:
......
{field: 'val_map', title: 'Value', sortable: true, width: 150,
// if row.key_editor=1 then type editor textbox
// elseif row.key_editor=2 then editor type checkbox
// ....
editor:{
                    type:'textbox',
                    options:{
                        icons:[{
                            iconCls: 'icon-new-win',
                            handler:function(){
                                var row = $('#dgKeyVal').datagrid('getSelected');
                                if(row.key_map=='LOGO'){
                                    //alert('Attach logo !');
                                    openDlgAttachFile();
                                }else{
                                    valMore();
                                }
                            }
                        }],
                    }
                }},
......

how got other column value in editor as above logical ?

Any help I appreciate it, Thanks.
« Last Edit: February 26, 2016, 11:01:55 PM by finzaiko » Logged
jarry
Administrator
Hero Member
*****
Posts: 2269


View Profile Email
« Reply #1 on: February 26, 2016, 08:49:42 AM »

Please extend a method 'getGridInfo' to get the datagrid information in a textbox.
Code:
<script type="text/javascript">
(function($){
  $.extend($.fn.textbox.methods, {
    getGridInfo: function(jq){
      var tr = $(jq[0]).closest('.datagrid-row');
      var view = tr.closest('.datagrid-view');
      var grid = view.children('.datagrid-f');
      return {
        grid: grid,
        index: parseInt(tr.attr('datagrid-row-index')),
        id: tr.attr('node-id')
      }
    }
  })
})(jQuery);
</script>

To get the editing row in the extra icon handler of the textbox, please try this:
Code:
editor:{
  type:'textbox',
  options:{
    icons:[{
      iconCls: 'icon-add',
      handler: function(e){
        var info = $(e.data.target).textbox('getGridInfo');
        var row = $(info.grid).datagrid('getRows')[info.index];
        console.log(row)
      }
    }]
  }
}
Logged
finzaiko
Newbie
*
Posts: 44


View Profile
« Reply #2 on: February 26, 2016, 09:03:45 PM »

Hi Jarry,

Thanks alot for your reply, maybe you misunderstood my point, I'm sorry about my question, I mean that
when I want to edit the current row by double-clicking the row, the editor will automatically change into checkbox if row.key_editor = 2, and if row.key_editor = 3 into the textbox and so on, I try using onBeginEdit event

Code:
var myTextEditor = {
       type:'textbox',
        options:{
            icons:[{
                iconCls: 'icon-new-win',
                handler:function(e){
                    var row = $('#dgKeyVal').datagrid('getSelected');
                    if(row.key_map=='LOGO'){
                        //alert('Attach logo !');
                        openDlgAttachFile();
                    }else{
                        valMore();
                    }
                }
            }],
        }
   };
   var myCheckEditor = {
       type:'checkbox',
       options: {on:1,off:0},
   };

// this is my column
{field: 'key_map', title: 'Key', width: 100, sortable: true},
{field: 'val_map', title: 'Value', editor: myTextEditor },  <<---- Change this editor
{field: 'key_editor', hidden: true},

onBeginEdit: function(index,row){
                if(row.key_editor==2){
                    //change val_map to checkbox editor
                    console.log('checkbox');
                    // this should be change to myCheckEditor
                }else{
                    console.log('textbox');
                    // this should be change to myTextEditor
                }
            },
« Last Edit: February 26, 2016, 09:08:44 PM by finzaiko » Logged
jarry
Administrator
Hero Member
*****
Posts: 2269


View Profile Email
« Reply #3 on: February 26, 2016, 10:54:34 PM »

You must change the 'editor' property before editing a row, so please use the 'onBeforeEdit' instead of 'onBeginEdit'.
Code:
$('#dg').datagrid({
onBeforeEdit: function(index,row){
var col = $(this).datagrid('getColumnOption', 'val_map');
if (row.key_editor==2){
col.editor = myTextEditor;
} else {
col.editor = myCheckEditor;
}
}
})
Logged
finzaiko
Newbie
*
Posts: 44


View Profile
« Reply #4 on: February 26, 2016, 11:01:18 PM »

Ahaa.. Its work!, solved, Thanks Jarry.
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!