EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: patana on March 27, 2015, 08:10:46 PM



Title: How to get Checkbox value from Datagrid editor
Post by: patana on March 27, 2015, 08:10:46 PM
Dear all,
How to get Checkbox value from Datagrid editor type=checkbox?
Thanks all.


Title: Re: How to get Checkbox value from Datagrid editor
Post by: stworthy on March 28, 2015, 05:40:57 AM
The 'checkbox' editor has 'on' and 'off' options that indicate the checked and unchecked values.
Code:
<th field="status" width="50" data-options="
editor:{
type:'checkbox',
options:{
on: 'P',
off: 'N'
}
}
">Status</th>


Title: Re: How to get Checkbox value from Datagrid editor
Post by: patana on March 30, 2015, 12:36:54 AM
Code:
<th data-options="field:'status',width:15"  align='center' editor="{type:'checkbox',options:{on:'v',off:'n'}}">status</th>
function getRowIndex(target) {
            var tr = $(target).closest('tr.datagrid-row');
            return parseInt(tr.attr('datagrid-row-index'));
        }
function saverow(target){
  var status = $('#dg').datagrid('getEditor', {index: getRowIndex(target), field: 'status'});
  var v_status = $(status.target).val();
  alert(v_status)
}
And the result i got is alway 'v' even i did not check it.


Title: Re: How to get Checkbox value from Datagrid editor
Post by: stworthy on March 30, 2015, 01:59:32 AM
You can use .is(':checked') to determine whether or not the checkbox editor is checked.
Code:
var status = $('#dg').datagrid('getEditor', {index: getRowIndex(target), field: 'status'});
if ($(status.target).is(':checked')){
  //...
}


Title: Re: How to get Checkbox value from Datagrid editor
Post by: patana on March 30, 2015, 02:05:22 AM
Ok, got it!
Thanks.