EasyUI Forum
April 26, 2024, 10:23:06 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: tagbox in datagrid  (Read 4262 times)
zombie86
Newbie
*
Posts: 24


View Profile WWW Email
« on: February 17, 2020, 10:56:18 PM »

Dear All,
please can you help me on how to use tagbox editor in datagrid

i do use for now a combobox and I need to change it to tagbox

Code:
<th style="width:30%;" data-options="field:'vendor_id',formatter:function(value,row){return row.vendor_name;},editor:{type:'combobox'}">Vendor Name</th>
<th style="width:30%;" data-options="field:'vendor_ids',tagFormatter:function(value,row){var opts=$(this).tagbox('options'); return row ? row[opts.textField] : value;},editor:{type:'tagbox'}">Vendor Name</th>

Code:
<script type="text/javascript">
    $('#dg_rfq_trans').datagrid({
        onBeforeEdit: function(rowIndex,row){
            var material = $('#dg_rfq_trans').datagrid('getColumnOption', 'material_id');
            material.editor = {
                type:'combobox',
                options:{
                    valueField:'id',
                    textField:'text',
                    method:'get',
                    data:accounts.material,
                    required:true,
                    value:row.material_id,
                    onChange:function(value){
                       
                    }
                }
            }
            var vendor = $('#dg_rfq_trans').datagrid('getColumnOption', 'vendor_id');
            vendor.editor = {
                type:'combobox',
                options:{
                    multiple:true,
                    valueField:'id',
                    textField:'text',
                    method:'get',
                    data:accounts.vendor,
                    required:true,
                    value:row.vendor_id,
                    onChange:function(value){
                       
                    }
                }
            }
            var vendors = $('#dg_rfq_trans').datagrid('getColumnOption', 'vendor_ids');
            vendors.editor = {
                type:'tagbox',
                options:{
                    data:accounts.vendor,
                    valueField:'id',
                    textField:'text',
                    value:row.vendor_id,
                    limitToList: true,
                    hasDownArrow: true
                }
            }
        }
    });
</script>
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: February 18, 2020, 01:37:40 AM »

Please extend the 'tagbox' editor before applying it.
Code:
$.extend($.fn.datagrid.defaults.editors, {
tagbox: {
init: function(container,options){
var input = $('<input>').appendTo(container);
input.tagbox(options);
return input;
},
destroy: function(target){
$(target).tagbox('destroy');
},
getValue: function(target){
return $(target).tagbox('getValues').join(',');
},
setValue: function(target, value){
if (value){
$(target).tagbox('setValues', value.split(','));
} else {
$(target).tagbox('clear');
}
},
resize: function(target, width){
$(target).tagbox('resize', width);
}
}
})
Logged
zombie86
Newbie
*
Posts: 24


View Profile WWW Email
« Reply #2 on: February 19, 2020, 09:31:06 PM »

thanks jarry,

you save my day, but when I set tagFormatter in markup way its not working properly, and returns the values instaed of textField

any suggestions?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #3 on: February 20, 2020, 10:58:41 PM »

The editor displays the tagbox component to edit and finally the datagrid will retrieve the values of the tagbox component. You should define the 'formatter' function on the column to display your expired text based on the field values.
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!