问题描述
您好我正在使用GXT 2.2.3创建可编辑网格。我创建了如下所示的列:
List< String> eventList = new ArrayList< String>();
eventList.add(Mark / Modify Attendance);
eventList.add(删除考勤);
eventList.add(修改名册);
eventList.add(Mark OD);
eventList.add(忘记登记);
eventcombo = new SimpleComboBox< String>();
eventcombo.setEmptyText();
eventcombo.setTriggerAction(TriggerAction.ALL);
// EventCombo.setSelection(eventList);
CellEditor eventComboEditor = new CellEditor(eventcombo){
public Object preProcessValue(Object value){
if(value == null){
返回值;
}
return eventcombo.findModel(value.toString());
}
public Object postProcessValue(Object value){
if(value == null){
return value; $(b)b
return((ModelData)value).get(value);
}
};
eventcombo.setForceSelection(true);
eventcombo.setEmptyText();
eventcombo.setTriggerAction(TriggerAction.ALL);
eventcombo.add(eventList);
ColumnConfig eventcolumn = new ColumnConfig();
eventcolumn.setId(event);
eventcolumn.setHeader(Event);
eventcolumn.setWidth(145);
eventcolumn.setMenuDisabled(true);
eventcolumn.setSortable(false);
/ * * /
// column.setEditor(new);
eventcolumn.setEditor(eventComboEditor);
configs.add(eventcolumn);
// rosterInOut-10
ColumnConfig rosterInOutcolumn = new ColumnConfig();
rosterInOutcolumn.setId(rosterInOut);
rosterInOutcolumn.setHeader(Old Roster);
rosterInOutcolumn.setWidth(70);
rosterInOutcolumn.setMenuDisabled(true);
rosterInOutcolumn.setSortable(false);
configs.add(rosterInOutcolumn);
Rostercombo = new SimpleComboBox< String>();
CellEditor editor1 = new CellEditor(Rostercombo){
public Object preProcessValue(Object value){
if(value == null){
return value;
}
return Rostercombo.findModel(value.toString());
}
public Object postProcessValue(Object value){
if(value == null){
return value; $(b)b
return((ModelData)value).get(value);
}
};
Rostercombo.setForceSelection(true);
Rostercombo.setTriggerAction(TriggerAction.ALL);
Rostercombo.add(OD);
Rostercombo.add(O);
// newRosterin-11
ColumnConfig newRosterincolumn = new ColumnConfig();
newRosterincolumn.setId(newRosterin);
newRosterincolumn.setHeader(New Roster In);
newRosterincolumn.setWidth(80);
newRosterincolumn.setEditor(editor1);
newRosterincolumn.setMenuDisabled(true);
newRosterincolumn.setSortable(false);
configs.add(newRosterincolumn);
// checkinout-12
ColumnConfig checkinoutcolumn = new ColumnConfig();
checkinoutcolumn.setId(checkinout);
checkinoutcolumn.setHeader(Check In-Out);
checkinoutcolumn.setWidth(80);
checkinoutcolumn.setMenuDisabled(true);
checkinoutcolumn.setSortable(false);
configs.add(checkinoutcolumn);
// checkinDate-13
ColumnConfig checkinDatecolumn = new ColumnConfig();
checkinDatecolumn.setId(checkinDate);
checkinDatecolumn.setHeader(签入日期);
checkinDatecolumn.setWidth(85);
checkinDatecolumn.setMenuDisabled(true);
checkinDatecolumn.setSortable(false);
final DateField dateField1 = new DateField();
dateField1.getPropertyEditor()。setFormat(DateTimeFormat.getFormat(dd / MMM / yyyy));
dateField1.getDatePicker()。addListener(Events.Select,new Listener< DatePickerEvent>(){
@Override
public void handleEvent(DatePickerEvent dpe){
// Window.alert(在此处获取名单日期 - >+ grid.getColumnModel()。);
Window.alert(Getting RosterDate - 。+ caseStoreModule.getModifiedRecords() .get(0).get(rosterDate));
});
checkinDatecolumn.setEditor(new CellEditor(dateField1));
checkinDatecolumn.setDateTimeFormat(DateTimeFormat.getFormat(dd / MMM / yyyy));
configs.add(checkinDatecolumn);
// checkinTime-14
ColumnConfig checkinTimecolumn = new ColumnConfig();
checkinTimecolumn.setId(checkinTime);
checkinTimecolumn.setHeader(Check In Time);
checkinTimecolumn.setWidth(80);
checkinTimecolumn.setMenuDisabled(true);
checkinTimecolumn.setSortable(false);
final TextField< String> checkintime = new TextField< String>();
checkintime.setAllowBlank(true);
checkintime.addListener(Events.Change,new Listener< BaseEvent>(){
@Override
public void handleEvent(BaseEvent be){
(获取签入时间值 - >+ checkintime.getValue());
字符串变量= checkintime.getRawValue();
if(variable!= null& !变量.equalsIgnoreCase())
{
if(!variable.matches(REG_EXP))
{
checkintime.clear();
MsgBox.info (以hh:mm格式输入时间);
checkintime.focus();
return;
}
}
}
});
checkinTimecolumn.setEditor(new CellEditor(checkintime));
configs.add(checkinTimecolumn);
// checkoutDate-15
ColumnConfig checkoutDatecolumn = new ColumnConfig();
checkoutDatecolumn.setId(checkoutDate);
checkoutDatecolumn.setHeader(签出日期);
checkoutDatecolumn.setWidth(90);
checkoutDatecolumn.setMenuDisabled(true);
checkoutDatecolumn.setSortable(false);
DateField dateField2 = new DateField();
dateField2.getPropertyEditor()。setFormat(DateTimeFormat.getFormat(dd / MMM / yyyy));
checkoutDatecolumn.setEditor(new CellEditor(dateField2));
checkoutDatecolumn.setDateTimeFormat(DateTimeFormat.getFormat(dd / MMM / yyyy));
configs.add(checkoutDatecolumn);
// checkoutTime-15
ColumnConfig checkoutTimecolumn = new ColumnConfig();
checkoutTimecolumn.setId(checkoutTime);
checkoutTimecolumn.setHeader(Check Out Time);
checkoutTimecolumn.setWidth(90);
checkoutTimecolumn.setMenuDisabled(true);
checkoutTimecolumn.setSortable(false);
final TextField< String> checkouttime = new TextField< String>();
checkouttime.setAllowBlank(true);
checkouttime.addListener(Events.Change,new Listener< BaseEvent>(){
@Override
public void handleEvent(BaseEvent be){
(获取checkouttime值 - >+ checkouttime.getValue());
字符串变量= checkouttime.getRawValue();
if(variable!= null&! ();
{
if(!variable.matches(REG_EXP))
{
checkouttime.clear();
MsgBox.info 输入时间以hh:mm格式);
checkouttime.focus();
return;
}
}
}
});
checkoutTimecolumn.setEditor(new CellEditor(checkouttime));
configs.add(checkoutTimecolumn);
//用于gradeCode-16
ColumnConfig gradeCodecolumn = new ColumnConfig();
gradeCodecolumn.setId(gradeCode);
gradeCodecolumn.setHidden(true);
configs.add(gradeCodecolumn);
//用于rosterevent-17
ColumnConfig rostereventcolumn = new ColumnConfig();
rostereventcolumn.setId(rosterevent);
rostereventcolumn.setHidden(true);
configs.add(rostereventcolumn);
//用于操作-18
ColumnConfig actioncolumn = new ColumnConfig();
actioncolumn.setId(action);
actioncolumn.setHeader(Action);
//column.setHidden(true);
actioncolumn.setWidth(70);
actioncolumn.setMenuDisabled(true);
actioncolumn.setSortable(false);
configs.add(actioncolumn);
//为actionHidden-19
ColumnConfig actionHiddencolumn = new ColumnConfig();
actionHiddencolumn.setId(actionHidden);
actionHiddencolumn.setHidden(true);
configs.add(actionHiddencolumn);
// for attendId-20
ColumnConfig attendIdcolumn = new ColumnConfig();
attendIdcolumn.setId(attendId);
attendIdcolumn.setHidden(true);
configs.add(attendIdcolumn);
//用于rosterChanged-21
ColumnConfig rosterChangedcolumn = new ColumnConfig();
rosterChangedcolumn.setId(rosterChanged);
rosterChangedcolumn.setHidden(true);
configs.add(rosterChangedcolumn);
//用于假期-22
ColumnConfig holidaycolumn = new ColumnConfig();
holidaycolumn.setId(假期);
holidaycolumn.setHidden(true);
configs.add(holidaycolumn);
// for checkinDateTimeHidden-23
column = new ColumnConfig();
column.setId(checkinDateTimeHidden);
column.setHidden(true);
configs.add(column);
//用于checkoutDateTimeHidden-24
ColumnConfig checkoutDateTimeHiddencolumn = new ColumnConfig();
checkoutDateTimeHiddencolumn.setId(checkoutDateTimeHidden);
checkoutDateTimeHiddencolumn.setHidden(true);
configs.add(checkoutDateTimeHiddencolumn);
// loginEmpEntity-25
ColumnConfig loginEmpEntitycolumn = new ColumnConfig();
loginEmpEntitycolumn.setId(loginEmpEntity);
loginEmpEntitycolumn.setHidden(true);
configs.add(loginEmpEntitycolumn);
// for halfDayLLimit-26
ColumnConfig halfDayLLimitcolumn = new ColumnConfig();
halfDayLLimitcolumn.setId(halfDayLLimit);
halfDayLLimitcolumn.setHidden(true);
configs.add(halfDayLLimitcolumn);
返回新的ColumnModel(configs);
$ / pre
$ b $ p现在我想根据
如何在eventCombo框的Listener中做到这一点。请提示。
我在下面的代码中尝试禁用并启用单元格,但它禁用单元格。但禁用后,如果我选择另一个,它不会再次启用。
监听器> gridAfterEditListener = new Listener>(){
@Override
public void handleEvent(GridEvent< AttendanceCaseCreationModel> be){
AttendanceCaseCreationModel data = be.getModel();
String val = data.get(event);
if(val.equalsIgnoreCase(Remove Attendance)){
data.set(checkinDate,);
grid.getColumnModel()。getColumnById(checkinDate)。getEditor()。disable();
grid.getStore()。update(data);
grid.getView()。refresh(true);
}
else {
data.set(checkinDate,);
grid.getColumnModel()。getColumnById(checkinDate)。getEditor()。enable();
grid.getStore()。update(data);
grid.getView()。refresh(true);
}
}
};
grid.addListener(Events.AfterEdit,gridAfterEditListener);
请建议如何解决此问题
解决方案相反,想到禁用和启用单元格,我只是使用CSS隐藏和显示单元格。
GridCellRenderer< AttendanceCaseCreationModel>下面是我的代码,它使我无法达到这个要求。 checkinRenderer = new GridCellRenderer< AttendanceCaseCreationModel>(){
@Override
public Object render(AttendanceCaseCreationModel model,String property,
ColumnData config,int rowIndex,int colIndex,
ListStore< AttendanceCaseCreationModel> store,
Grid< AttendanceCaseCreationModel> grid){
String color =pink;
if(eventcombo.getValue()!= null){
if(eventcombo.getRawValue()。equalsIgnoreCase(忘记检入)||
eventcombo.getRawValue()。equalsIgnoreCase(Mark / Modify Attendance)){
color =pink;
}
else {
config.style = config.style +; visibility:hidden;;
}
}
config.style = config.style +; background-color:+ color +;;
config.style = config.style +; display:block;;
Object value = model.get(property);
返回值;
}
};
Hi I am creating Editable Grid using GXT 2.2.3. I created columns like below:
List<String> eventList=new ArrayList<String>();
eventList.add("Mark/Modify Attendance");
eventList.add("Remove Attendance");
eventList.add("Modify Roster");
eventList.add("Mark OD");
eventList.add("Forgot To Checkin");
eventcombo = new SimpleComboBox<String>();
eventcombo.setEmptyText("");
eventcombo.setTriggerAction(TriggerAction.ALL);
// EventCombo.setSelection(eventList);
CellEditor eventComboEditor = new CellEditor(eventcombo) {
public Object preProcessValue(Object value) {
if (value == null) {
return value;
}
return eventcombo.findModel(value.toString());
}
public Object postProcessValue(Object value) {
if (value == null) {
return value;
}
return ((ModelData) value).get("value");
}
};
eventcombo.setForceSelection(true);
eventcombo.setEmptyText("");
eventcombo.setTriggerAction(TriggerAction.ALL);
eventcombo.add(eventList);
ColumnConfig eventcolumn = new ColumnConfig();
eventcolumn.setId("event");
eventcolumn.setHeader("Event");
eventcolumn.setWidth(145);
eventcolumn.setMenuDisabled(true);
eventcolumn.setSortable(false);
/* */
// column.setEditor(new);
eventcolumn.setEditor(eventComboEditor);
configs.add(eventcolumn);
//rosterInOut-10
ColumnConfig rosterInOutcolumn = new ColumnConfig();
rosterInOutcolumn.setId("rosterInOut");
rosterInOutcolumn.setHeader("Old Roster");
rosterInOutcolumn.setWidth(70);
rosterInOutcolumn.setMenuDisabled(true);
rosterInOutcolumn.setSortable(false);
configs.add(rosterInOutcolumn);
Rostercombo = new SimpleComboBox<String>();
CellEditor editor1 = new CellEditor(Rostercombo) {
public Object preProcessValue(Object value) {
if (value == null) {
return value;
}
return Rostercombo.findModel(value.toString());
}
public Object postProcessValue(Object value) {
if (value == null) {
return value;
}
return ((ModelData) value).get("value");
}
};
Rostercombo.setForceSelection(true);
Rostercombo.setTriggerAction(TriggerAction.ALL);
Rostercombo.add("OD");
Rostercombo.add("O");
//newRosterin-11
ColumnConfig newRosterincolumn = new ColumnConfig();
newRosterincolumn.setId("newRosterin");
newRosterincolumn.setHeader("New Roster In");
newRosterincolumn.setWidth(80);
newRosterincolumn.setEditor(editor1);
newRosterincolumn.setMenuDisabled(true);
newRosterincolumn.setSortable(false);
configs.add(newRosterincolumn);
//checkinout-12
ColumnConfig checkinoutcolumn = new ColumnConfig();
checkinoutcolumn.setId("checkinout");
checkinoutcolumn.setHeader("Check In-Out");
checkinoutcolumn.setWidth(80);
checkinoutcolumn.setMenuDisabled(true);
checkinoutcolumn.setSortable(false);
configs.add(checkinoutcolumn);
//checkinDate-13
ColumnConfig checkinDatecolumn = new ColumnConfig();
checkinDatecolumn.setId("checkinDate");
checkinDatecolumn.setHeader("Check In Date");
checkinDatecolumn.setWidth(85);
checkinDatecolumn.setMenuDisabled(true);
checkinDatecolumn.setSortable(false);
final DateField dateField1 = new DateField();
dateField1.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MMM/yyyy"));
dateField1.getDatePicker().addListener(Events.Select, new Listener<DatePickerEvent>() {
@Override
public void handleEvent(DatePickerEvent dpe) {
// Window.alert("Getting Roster Date here-->"+grid.getColumnModel().);
Window.alert("Getting RosterDate--."+ caseStoreModule.getModifiedRecords().get(0).get("rosterDate"));
}
});
checkinDatecolumn.setEditor(new CellEditor(dateField1));
checkinDatecolumn.setDateTimeFormat(DateTimeFormat.getFormat("dd/MMM/yyyy"));
configs.add(checkinDatecolumn);
//checkinTime-14
ColumnConfig checkinTimecolumn=new ColumnConfig();
checkinTimecolumn.setId("checkinTime");
checkinTimecolumn.setHeader("Check In Time");
checkinTimecolumn.setWidth(80);
checkinTimecolumn.setMenuDisabled(true);
checkinTimecolumn.setSortable(false);
final TextField<String> checkintime = new TextField<String>();
checkintime.setAllowBlank(true);
checkintime.addListener(Events.Change, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
// Window.alert("getting the checkin time value-->"+checkintime.getValue());
String variable = checkintime.getRawValue();
if(variable != null & !variable.equalsIgnoreCase(""))
{
if(!variable.matches(REG_EXP))
{
checkintime.clear();
MsgBox.info("Enter time in hh:mm format");
checkintime.focus();
return;
}
}
}
});
checkinTimecolumn.setEditor(new CellEditor(checkintime));
configs.add(checkinTimecolumn);
//checkoutDate-15
ColumnConfig checkoutDatecolumn=new ColumnConfig();
checkoutDatecolumn.setId("checkoutDate");
checkoutDatecolumn.setHeader("Check Out Date");
checkoutDatecolumn.setWidth(90);
checkoutDatecolumn.setMenuDisabled(true);
checkoutDatecolumn.setSortable(false);
DateField dateField2 = new DateField();
dateField2.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MMM/yyyy"));
checkoutDatecolumn.setEditor(new CellEditor(dateField2));
checkoutDatecolumn.setDateTimeFormat(DateTimeFormat.getFormat("dd/MMM/yyyy"));
configs.add(checkoutDatecolumn);
//checkoutTime-15
ColumnConfig checkoutTimecolumn=new ColumnConfig();
checkoutTimecolumn.setId("checkoutTime");
checkoutTimecolumn.setHeader("Check Out Time");
checkoutTimecolumn.setWidth(90);
checkoutTimecolumn.setMenuDisabled(true);
checkoutTimecolumn.setSortable(false);
final TextField<String> checkouttime = new TextField<String>();
checkouttime.setAllowBlank(true);
checkouttime.addListener(Events.Change, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
// Window.alert("getting the checkouttime value-->"+checkouttime.getValue());
String variable = checkouttime.getRawValue();
if(variable != null & !variable.equalsIgnoreCase(""))
{
if(!variable.matches(REG_EXP))
{
checkouttime.clear();
MsgBox.info("Enter time in hh:mm format");
checkouttime.focus();
return;
}
}
}
});
checkoutTimecolumn.setEditor(new CellEditor(checkouttime));
configs.add(checkoutTimecolumn);
//for gradeCode-16
ColumnConfig gradeCodecolumn=new ColumnConfig();
gradeCodecolumn.setId("gradeCode");
gradeCodecolumn.setHidden(true);
configs.add(gradeCodecolumn);
//for rosterevent-17
ColumnConfig rostereventcolumn=new ColumnConfig();
rostereventcolumn.setId("rosterevent");
rostereventcolumn.setHidden(true);
configs.add(rostereventcolumn);
//for action-18
ColumnConfig actioncolumn=new ColumnConfig();
actioncolumn.setId("action");
actioncolumn.setHeader("Action");
//column.setHidden(true);
actioncolumn.setWidth(70);
actioncolumn.setMenuDisabled(true);
actioncolumn.setSortable(false);
configs.add(actioncolumn);
//for actionHidden-19
ColumnConfig actionHiddencolumn=new ColumnConfig();
actionHiddencolumn.setId("actionHidden");
actionHiddencolumn.setHidden(true);
configs.add(actionHiddencolumn);
//for attendId-20
ColumnConfig attendIdcolumn=new ColumnConfig();
attendIdcolumn.setId("attendId");
attendIdcolumn.setHidden(true);
configs.add(attendIdcolumn);
//for rosterChanged-21
ColumnConfig rosterChangedcolumn=new ColumnConfig();
rosterChangedcolumn.setId("rosterChanged");
rosterChangedcolumn.setHidden(true);
configs.add(rosterChangedcolumn);
// for holiday-22
ColumnConfig holidaycolumn=new ColumnConfig();
holidaycolumn.setId("holiday");
holidaycolumn.setHidden(true);
configs.add(holidaycolumn);
// for checkinDateTimeHidden-23
column=new ColumnConfig();
column.setId("checkinDateTimeHidden");
column.setHidden(true);
configs.add(column);
// for checkoutDateTimeHidden-24
ColumnConfig checkoutDateTimeHiddencolumn=new ColumnConfig();
checkoutDateTimeHiddencolumn.setId("checkoutDateTimeHidden");
checkoutDateTimeHiddencolumn.setHidden(true);
configs.add(checkoutDateTimeHiddencolumn);
// for loginEmpEntity-25
ColumnConfig loginEmpEntitycolumn=new ColumnConfig();
loginEmpEntitycolumn.setId("loginEmpEntity");
loginEmpEntitycolumn.setHidden(true);
configs.add(loginEmpEntitycolumn);
// for halfDayLLimit-26
ColumnConfig halfDayLLimitcolumn=new ColumnConfig();
halfDayLLimitcolumn.setId("halfDayLLimit");
halfDayLLimitcolumn.setHidden(true);
configs.add(halfDayLLimitcolumn);
return new ColumnModel(configs);
Now I want to make the checkinDate,CheckIntime,CheckOutDate and CheckOutTime column cells as Noneditable or disabled based on value of eventCombo box value.
How to make this in the Listener of eventCombo box.Please suggest.
I tried below code to disable and enable the cell but it's disabling cell fine.But after disabling,if I choose another it's not enabling again.
Listener> gridAfterEditListener = new Listener>() {
@Override
public void handleEvent(GridEvent<AttendanceCaseCreationModel> be) {
AttendanceCaseCreationModel data = be.getModel();
String val = data.get("event");
if(val.equalsIgnoreCase("Remove Attendance")){
data.set("checkinDate","");
grid.getColumnModel().getColumnById("checkinDate").getEditor().disable();
grid.getStore().update(data);
grid.getView().refresh(true);
}
else {
data.set("checkinDate","");
grid.getColumnModel().getColumnById("checkinDate").getEditor().enable();
grid.getStore().update(data);
grid.getView().refresh(true);
}
}
};
grid.addListener(Events.AfterEdit, gridAfterEditListener);
Please suggest how to resolve this
解决方案 Instead thinking of disabling and enabling the cell, I just hide and show the cell using CSS. Below is my code which saves me to reach this requirement.
GridCellRenderer<AttendanceCaseCreationModel> checkinRenderer=new GridCellRenderer<AttendanceCaseCreationModel>() {
@Override
public Object render(AttendanceCaseCreationModel model, String property,
ColumnData config, int rowIndex, int colIndex,
ListStore<AttendanceCaseCreationModel> store,
Grid<AttendanceCaseCreationModel> grid) {
String color="pink";
if(eventcombo.getValue()!=null){
if(eventcombo.getRawValue().equalsIgnoreCase("Forgot To Checkin") ||
eventcombo.getRawValue().equalsIgnoreCase("Mark/Modify Attendance")){
color="pink";
}
else{
config.style=config.style+ ";visibility: hidden;";
}
}
config.style=config.style+ ";background-color:" + color + ";";
config.style=config.style+ ";display: block;";
Object value = model.get(property);
return value;
}
};
这篇关于如何根据gxt中可编辑网格中的另一个单元格值将单元格设置为不可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!