EasyUI Forum
April 29, 2024, 08:00: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: Enable/disable checkbox on Combobox change in editable datagrid  (Read 1137 times)
iLLuSia
Newbie
*
Posts: 12


View Profile Email
« on: February 13, 2023, 08:06:00 AM »

Hello,

I have an editable Datagrid with (among others) a Combobox column and what's supposed to be a checkbox soon (the labassist one), and I want to enable or disable the checkbox individually for each row, depending on what is initially selected or gets selected in the Combobox.

Is this doable? I don't fully understand how to access both the Checkbox or Combobox later.

By the way, all rows from the datagrid are editable at the same time. I'm not sure whether thats important.
Code snippets:
Code:
$('#dg-manageruns').datagrid({
onLoadSuccess: function(data) {
for (var i=0; i<$(this).datagrid('getData').rows.length; i++) {
$(this).datagrid('beginEdit', i);
}
},
columns: [[
{field: 'labassist', title: 'Assist', sortable: true,
formatter:function(value, row, index) {
return value==1 ? "X" : value==0 ? "" : value;
},
// editor:{ (.............)
},
{field: 'setup', title: 'Setup', sortable: true, width:180,
editor:{
type:'combobox',
options:{
valueField:'id', textField:'setupname', data: listsetups, panelWidth:320,
}
}
},
(...)
Thanks for any help.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: February 14, 2023, 12:24:49 AM »

This example shows how to build the cascade editors according to some logic.
Code:
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>Basic DataGrid - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/material-blue/easyui.css">
<link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
<script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.min.js"></script>
<script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<script>
var data = [
{ labassist: '1', setup: 'setup1', setupname: 'Setupname1' },
{ labassist: '0', setup: 'setup2', setupname: 'Setupname2' },
{ labassist: '1', setup: 'setup1', setupname: 'Setupname1' },
{ labassist: '0', setup: 'setup4', setupname: 'Setupname4' },
{ labassist: '0', setup: 'setup5', setupname: 'Setupname5' }
];
var listsetups = [
{ id: 'setup1', 'setupname': 'Setupname1' },
{ id: 'setup2', 'setupname': 'Setupname2' },
{ id: 'setup3', 'setupname': 'Setupname3' },
{ id: 'setup4', 'setupname': 'Setupname4' },
{ id: 'setup5', 'setupname': 'Setupname5' }
];
$.extend($.fn.datagrid.defaults.editors, {
check: {
init: function (container, options) {
var input = $('<input type="text" class="datagrid-editable-input">').appendTo(container);
input.checkbox(options || {});
return input;
},
getValue: function (target) {
return $(target).checkbox('options').checked ? '1' : '0';
},
setValue: function (target, value) {
if (parseInt(value)) {
$(target).checkbox('check');
} else {
$(target).checkbox('uncheck');
}
},
resize: function (target, width) {
$(target).next().css('height', 20);
}
}
});
$(function () {
var dg = $('#dg-manageruns');
dg.datagrid({
columns: [[
{
field: 'labassist', title: 'Assist', align: 'center'
},
{
field: 'setup', title: 'Setup', width: 180
}
]],
data: data,
singleSelect: true,
onLoadSuccess: function (data) {
for (var i = 0; i < $(this).datagrid('getData').rows.length; i++) {
$(this).datagrid('beginEdit', i);
}
},
onBeforeEdit: function (index, row) {
var opts = $(this).datagrid('getColumnOption', 'labassist');
opts.editor = {
type: 'check',
options: {
value: row.labassist,
checked: row.labassist == '1',
disabled: row.setup != 'setup1'
}
}
var opts = $(this).datagrid('getColumnOption', 'setup');
opts.editor = {
type: 'combobox',
options: {
value: row.setup,
valueField: 'id', textField: 'setupname', data: listsetups, panelWidth: 320,
limitToList: true,
editable: false,
onChange: function (value) {
var tr = $(this).closest('.datagrid-row');
var index = tr.attr('datagrid-row-index');
setTimeout(function () {
dg.datagrid('endEdit', index).datagrid('beginEdit', index);
}, 0)
}
}
}
}
})
})

</script>
</head>

<body>
<table id="dg-manageruns" style="width:700px;height:250px"></table>

</body>

</html>
Logged
iLLuSia
Newbie
*
Posts: 12


View Profile Email
« Reply #2 on: March 06, 2023, 10:43:44 PM »

Thank you very much for this extensive example. It works now.
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!