Title: Change editor edatagrid [SOLVED]
Post by: finzaiko on February 26, 2016, 04:18:14 AM
How change editor in edatagrid depent on other value ...... {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.
Title: Re: Change editor edatagrid
Post by: jarry on February 26, 2016, 08:49:42 AM
Please extend a method 'getGridInfo' to get the datagrid information in a textbox. <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: 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) } }] } }
Title: Re: Change editor edatagrid
Post by: finzaiko 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 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 } },
Title: Re: Change editor edatagrid
Post by: jarry 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'. $('#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; } } })
Title: Re: Change editor edatagrid
Post by: finzaiko on February 26, 2016, 11:01:18 PM
Ahaa.. Its work!, solved, Thanks Jarry.
|